← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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