← Functions lesson New set →

App Dev Worksheet: Functions

App development lesson 20: Functions · Set 807 · 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 return do in a function? (a) repeats the code (b) sends back a value (c) deletes the app (d) closes the screen
  2. 2.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(6));
  3. 3.🧰 Why write a function? (a) to slow the app (b) to make code longer (c) to reuse code (d) to hide errors
  4. 4.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(18));
  5. 5.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(15));
  6. 6.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(7));
  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 50;
    }
    show(fee(11) + fee(12));
  8. 8.🧰 What does this code show?
    function greet(name) {
      return "Hello, " + name + "!";
    }
    show(greet("Riya"));
    (a) Hello, name! (b) Hello, Riya! (c) Riya (d) greet
  9. 9.🧰 What is a function? (a) a type of phone (b) a list of colours (c) a named block of code (d) a screen size
  10. 10.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(5));
  11. 11.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(4) + points(5));
  12. 12.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(9));
  13. 13.🧰 What does this code show?
    function greet(name) {
      return "Hello, " + name + "!";
    }
    show(greet("Meera"));
    (a) greet (b) Hello, Meera! (c) Hello, name! (d) Meera
  14. 14.🧰 In function tip(bill), what is bill? (a) a loop (b) a screen (c) a parameter (d) an event
  15. 15.🧰 What does this code show?
    function greet(name) {
      return "Well done, " + name + "!";
    }
    show(greet("Aman"));
    (a) greet (b) Well done, Aman! (c) Aman (d) Well done, name!
  16. 16.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(70, 6));
  17. 17.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(3) + points(1));
  18. 18.🧰 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(2) + fee(3));
  19. 19.🧰 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(8) + fee(8));
  20. 20.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(1) + points(3));
  21. 21.🧰 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(12) + fee(2));
  22. 22.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(3));
  23. 23.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(26));
  24. 24.🧰 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(11) + fee(1));
  25. 25.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(5) + points(3));
  26. 26.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(65, 6));
  27. 27.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(80, 5));
  28. 28.🧰 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(4) + fee(8));
  29. 29.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(7));
  30. 30.🧰 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(9) + fee(2));
  31. 31.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(5) + points(1));
  32. 32.🧰 What number does this code show?
    function double(n) {
      return n * 2;
    }
    show(double(11));
  33. 33.🧰 What number does this code show?
    function triple(n) {
      return n * 3;
    }
    show(triple(31));
  34. 34.🧰 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(5) + fee(3));
  35. 35.🧰 What does this code show?
    function greet(name) {
      return "Welcome, " + name + "!";
    }
    show(greet("Riya"));
    (a) Riya (b) Welcome, name! (c) Welcome, Riya! (d) greet
  36. 36.🧰 What does this code show?
    function greet(name) {
      return "Well done, " + name + "!";
    }
    show(greet("Riya"));
    (a) Well done, name! (b) Riya (c) Well done, Riya! (d) greet
  37. 37.🧰 How do you run (call) a function called greet? (a) #greet (b) greet[] (c) run greet (d) greet()
  38. 38.🧰 What number does this code show?
    function points(stars) {
      return stars * 10 + 5;
    }
    show(points(3) + points(3));
  39. 39.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(85, 3));
  40. 40.🧰 What number does this code show?
    function total(price, qty) {
      return price * qty;
    }
    show(total(15, 4));

Answer key

  1. sends back a value
  2. 18
  3. to reuse code
  4. 54
  5. 30
  6. 21
  7. 100
  8. Hello, Riya!
  9. a named block of code
  10. 15
  11. 100
  12. 18
  13. Hello, Meera!
  14. a parameter
  15. Well done, Aman!
  16. 420
  17. 50
  18. 0
  19. 40
  20. 50
  21. 30
  22. 6
  23. 78
  24. 50
  25. 90
  26. 390
  27. 400
  28. 30
  29. 14
  30. 50
  31. 70
  32. 22
  33. 93
  34. 30
  35. Welcome, Riya!
  36. Well done, Riya!
  37. greet()
  38. 70
  39. 255
  40. 60

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