← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 20
  2. 60
  3. 70
  4. 200
  5. 150
  6. 90
  7. greet()
  8. 75
  9. 425
  10. 36
  11. 50
  12. 80
  13. 450
  14. Hello, Meera!
  15. a named block of code
  16. 0
  17. Hi, Riya!
  18. 40
  19. 80
  20. 40
  21. 90
  22. 26
  23. 270
  24. 80
  25. sends back a value
  26. 30
  27. 120
  28. Hi, Meera!
  29. to reuse code
  30. 255
  31. 24
  32. 45
  33. 30
  34. a parameter
  35. 190
  36. Hello, Zoya!
  37. 100
  38. 400
  39. 150
  40. 475

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