← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. greet()
  2. a parameter
  3. 26
  4. 50
  5. 40
  6. 225
  7. 40
  8. a named block of code
  9. 54
  10. 60
  11. 130
  12. Hi, Riya!
  13. 45
  14. Hello, Riya!
  15. 20
  16. 60
  17. 300
  18. 100
  19. to reuse code
  20. 0
  21. 108
  22. 27
  23. Well done, Aman!
  24. 80
  25. sends back a value
  26. Hi, Kabir!
  27. 60
  28. 540
  29. 28
  30. 111
  31. 44
  32. 66
  33. Well done, Arjun!
  34. 30
  35. Welcome, Zoya!
  36. 165
  37. 140
  38. 100
  39. 60
  40. 74

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