← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. to reuse code
  2. 84
  3. 480
  4. 275
  5. 40
  6. sends back a value
  7. a parameter
  8. 240
  9. 70
  10. Hello, Riya!
  11. a named block of code
  12. greet()
  13. 80
  14. Well done, Kabir!
  15. Well done, Riya!
  16. 100
  17. 58
  18. 32
  19. 360
  20. 69
  21. 90
  22. 50
  23. 50
  24. 45
  25. 330
  26. 20
  27. 30
  28. 30
  29. 340
  30. 60
  31. 20
  32. Well done, Meera!
  33. Hi, Aman!
  34. 360
  35. Hi, Meera!
  36. 74
  37. Welcome, Kabir!
  38. 10
  39. Well done, Zoya!
  40. 15

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