← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 100
  2. 20
  3. Hi, Arjun!
  4. 12
  5. 70
  6. sends back a value
  7. 120
  8. 87
  9. 50
  10. 30
  11. 120
  12. a parameter
  13. 300
  14. 400
  15. 30
  16. 18
  17. 100
  18. 78
  19. 30
  20. 108
  21. 40
  22. to reuse code
  23. 140
  24. 90
  25. Hello, Riya!
  26. 60
  27. 40
  28. 32
  29. a named block of code
  30. 20
  31. 0
  32. 70
  33. 60
  34. 74
  35. 10
  36. 26
  37. 110
  38. 40
  39. 200
  40. greet()

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