← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 80
  2. 220
  3. greet()
  4. 50
  5. 68
  6. 14
  7. Welcome, Riya!
  8. Welcome, Zoya!
  9. 80
  10. 26
  11. to reuse code
  12. 60
  13. 70
  14. Hello, Zoya!
  15. 20
  16. 50
  17. 87
  18. Welcome, Aman!
  19. 90
  20. 6
  21. Hello, Kabir!
  22. 28
  23. 480
  24. 110
  25. 72
  26. 48
  27. a named block of code
  28. 46
  29. 80
  30. sends back a value
  31. 270
  32. 40
  33. a parameter
  34. 24
  35. 150
  36. 140
  37. 20
  38. 8
  39. 18
  40. 30

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