← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 40
  2. a parameter
  3. 120
  4. 120
  5. 275
  6. 30
  7. 48
  8. Hi, Riya!
  9. 50
  10. 20
  11. a named block of code
  12. 80
  13. Hi, Arjun!
  14. 12
  15. 50
  16. Welcome, Riya!
  17. Hello, Riya!
  18. 78
  19. sends back a value
  20. 90
  21. 60
  22. 360
  23. 76
  24. Hello, Meera!
  25. 70
  26. 50
  27. 300
  28. 190
  29. 40
  30. 50
  31. 48
  32. to reuse code
  33. 120
  34. 20
  35. 450
  36. 90
  37. 40
  38. 8
  39. 20
  40. 75

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