← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a parameter
  2. 100
  3. 140
  4. Hi, Kabir!
  5. 60
  6. sends back a value
  7. a named block of code
  8. Welcome, Riya!
  9. 50
  10. 150
  11. 44
  12. 105
  13. 117
  14. 70
  15. 80
  16. Hello, Aman!
  17. 80
  18. greet()
  19. Hello, Zoya!
  20. 180
  21. 24
  22. to reuse code
  23. 425
  24. Well done, Zoya!
  25. 0
  26. 40
  27. 60
  28. 21
  29. 56
  30. 70
  31. 50
  32. Hello, Kabir!
  33. 64
  34. 175
  35. 70
  36. 12
  37. 40
  38. 120
  39. 480
  40. 0

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