← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 105
  2. a named block of code
  3. 100
  4. 80
  5. a parameter
  6. 20
  7. Welcome, Arjun!
  8. Hello, Aman!
  9. 63
  10. 60
  11. Hi, Zoya!
  12. greet()
  13. to reuse code
  14. 450
  15. sends back a value
  16. 40
  17. 50
  18. 600
  19. 175
  20. Well done, Arjun!
  21. Well done, Aman!
  22. Well done, Meera!
  23. 30
  24. Well done, Zoya!
  25. Well done, Riya!
  26. Hi, Riya!
  27. 0
  28. 30
  29. 150
  30. 48
  31. 50
  32. 18
  33. Hello, Riya!
  34. 340
  35. 80
  36. 240
  37. Hello, Meera!
  38. Hi, Aman!
  39. 80
  40. 60

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