← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 80
  2. 30
  3. 160
  4. 30
  5. 100
  6. 80
  7. 30
  8. a named block of code
  9. Well done, Zoya!
  10. 0
  11. 420
  12. 0
  13. 60
  14. greet()
  15. to reuse code
  16. 114
  17. 300
  18. 8
  19. 200
  20. Hello, Aman!
  21. 60
  22. 120
  23. Hello, Arjun!
  24. 120
  25. 100
  26. 10
  27. 570
  28. 70
  29. Hello, Riya!
  30. 70
  31. 50
  32. 60
  33. Welcome, Aman!
  34. 90
  35. a parameter
  36. 60
  37. 66
  38. 9
  39. 0
  40. 120

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