← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 260
  2. 0
  3. a parameter
  4. Welcome, Arjun!
  5. sends back a value
  6. 420
  7. 400
  8. 240
  9. 30
  10. 330
  11. 510
  12. 63
  13. Hello, Aman!
  14. Well done, Aman!
  15. 0
  16. 300
  17. 20
  18. 74
  19. Welcome, Kabir!
  20. a named block of code
  21. 12
  22. 24
  23. 38
  24. to reuse code
  25. greet()
  26. 350
  27. 44
  28. 40
  29. 60
  30. 48
  31. 96
  32. Well done, Kabir!
  33. 120
  34. 70
  35. 70
  36. 80
  37. 52
  38. 150
  39. 6
  40. 30

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