← Functions lesson New set →

App Dev Worksheet: Functions

App development lesson 20: Functions · Set 459 · 40 questions
TalentJR

Developer's tip (Write once, use often): function name(parameter) { …; return result; } — call it with name(value). Work out each call separately, then finish the line. Inside a function, if / return can give different results for different inputs.

NameDateTime takenScore ___ / 40
  1. 1.🧰 What does this code show?
    function greet(name) {
      return "Well done, " + name + "!";
    }
    show(greet("Zoya"));
    (a) Well done, Zoya! (b) Well done, name! (c) Zoya (d) greet
  2. 2.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(11));
  3. 3.🧰 What is a function? (a) a list of colours (b) a named block of code (c) a type of phone (d) a screen size
  4. 4.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 20;
    }
    show(fee(9) + fee(1));
  5. 5.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 60;
    }
    show(fee(5) + fee(2));
  6. 6.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(50, 6));
  7. 7.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 20;
    }
    show(fee(3) + fee(1));
  8. 8.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 20;
    }
    show(fee(12) + fee(11));
  9. 9.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(4) + points(0));
  10. 10.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(30, 3));
  11. 11.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(50, 5));
  12. 12.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(1) + points(4));
  13. 13.🧰 What does this code show?
    function greet(name) {
      return "Welcome, " + name + "!";
    }
    show(greet("Kabir"));
    (a) Welcome, Kabir! (b) Kabir (c) greet (d) Welcome, name!
  14. 14.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(22));
  15. 15.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(17));
  16. 16.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(23));
  17. 17.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(3));
  18. 18.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(19));
  19. 19.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(2) + points(0));
  20. 20.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(100, 3));
  21. 21.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(25, 4));
  22. 22.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(30));
  23. 23.🧰 How do you run (call) a function called greet? (a) greet() (b) run greet (c) #greet (d) greet[]
  24. 24.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(70, 5));
  25. 25.🧰 What does this code show?
    function greet(name) {
      return "Hello, " + name + "!";
    }
    show(greet("Meera"));
    (a) Meera (b) Hello, name! (c) greet (d) Hello, Meera!
  26. 26.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(65, 5));
  27. 27.🧰 What does this code show?
    function greet(name) {
      return "Well done, " + name + "!";
    }
    show(greet("Riya"));
    (a) Riya (b) greet (c) Well done, name! (d) Well done, Riya!
  28. 28.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(30, 6));
  29. 29.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 50;
    }
    show(fee(7) + fee(2));
  30. 30.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(4) + points(1));
  31. 31.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(4) + points(3));
  32. 32.🧰 A museum app works out the entry fee. What number does this code show?
    function fee(age) {
      if (age < 5) {
        return 0;
      }
      return 30;
    }
    show(fee(9) + fee(1));
  33. 33.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(2) + points(3));
  34. 34.🧰 In function tip(bill), what is bill? (a) a parameter (b) a loop (c) a screen (d) an event
  35. 35.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(8));
  36. 36.🧰 What does return do in a function? (a) sends back a value (b) repeats the code (c) closes the screen (d) deletes the app
  37. 37.🧰 What does this code show?
    function greet(name) {
      return "Welcome, " + name + "!";
    }
    show(greet("Meera"));
    (a) greet (b) Meera (c) Welcome, name! (d) Welcome, Meera!
  38. 38.🧰 What does this code show?
    function greet(name) {
      return "Welcome, " + name + "!";
    }
    show(greet("Arjun"));
    (a) Welcome, name! (b) Arjun (c) Welcome, Arjun! (d) greet
  39. 39.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(15, 4));
  40. 40.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(90, 6));

Answer key

  1. Well done, Zoya!
  2. 33
  3. a named block of code
  4. 20
  5. 60
  6. 300
  7. 0
  8. 40
  9. 50
  10. 90
  11. 250
  12. 60
  13. Welcome, Kabir!
  14. 66
  15. 51
  16. 46
  17. 9
  18. 38
  19. 30
  20. 300
  21. 100
  22. 60
  23. greet()
  24. 350
  25. Hello, Meera!
  26. 325
  27. Well done, Riya!
  28. 180
  29. 50
  30. 60
  31. 80
  32. 30
  33. 60
  34. a parameter
  35. 16
  36. sends back a value
  37. Welcome, Meera!
  38. Welcome, Arjun!
  39. 60
  40. 540

Free app development lessons, practice and worksheets at talentjr.in/app-development-for-students