← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 60
  2. 60
  3. a parameter
  4. 40
  5. 87
  6. sends back a value
  7. 39
  8. 8
  9. 74
  10. Hi, Riya!
  11. 240
  12. 30
  13. 400
  14. 300
  15. Hello, Aman!
  16. 20
  17. a named block of code
  18. to reuse code
  19. Welcome, Zoya!
  20. Well done, Meera!
  21. Well done, Kabir!
  22. Hi, Meera!
  23. 70
  24. Hi, Kabir!
  25. 42
  26. 20
  27. 140
  28. 240
  29. 100
  30. 30
  31. 70
  32. 375
  33. 18
  34. Welcome, Riya!
  35. 220
  36. 30
  37. 78
  38. 0
  39. 40
  40. greet()

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