← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 70
  2. greet()
  3. 100
  4. 100
  5. 100
  6. 270
  7. to reuse code
  8. 60
  9. 300
  10. 120
  11. 26
  12. 8
  13. 72
  14. 105
  15. 60
  16. 30
  17. 90
  18. Welcome, Meera!
  19. a named block of code
  20. Hi, Meera!
  21. 80
  22. Well done, Kabir!
  23. 200
  24. 20
  25. 80
  26. 30
  27. 70
  28. Well done, Riya!
  29. sends back a value
  30. 68
  31. 70
  32. 114
  33. a parameter
  34. 33
  35. Hi, Riya!
  36. 425
  37. Hi, Zoya!
  38. 24
  39. Welcome, Kabir!
  40. 64

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