← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 60
  2. 66
  3. 300
  4. 50
  5. 240
  6. sends back a value
  7. 210
  8. 160
  9. 93
  10. Hello, Riya!
  11. Hello, Aman!
  12. 0
  13. 50
  14. Welcome, Aman!
  15. 450
  16. 340
  17. Hi, Riya!
  18. 120
  19. 18
  20. 100
  21. 100
  22. 21
  23. 80
  24. 275
  25. a parameter
  26. 150
  27. 225
  28. Hello, Arjun!
  29. a named block of code
  30. greet()
  31. 180
  32. Hello, Meera!
  33. 180
  34. 54
  35. 30
  36. 56
  37. 63
  38. 105
  39. 0
  40. 350

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