← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 60
  2. 72
  3. sends back a value
  4. Well done, Riya!
  5. 90
  6. 450
  7. to reuse code
  8. Hi, Aman!
  9. Welcome, Arjun!
  10. 300
  11. greet()
  12. 60
  13. 70
  14. Hello, Riya!
  15. 60
  16. Hello, Kabir!
  17. Hello, Zoya!
  18. Hello, Aman!
  19. 28
  20. a parameter
  21. 210
  22. 80
  23. a named block of code
  24. Well done, Kabir!
  25. 75
  26. 100
  27. 40
  28. 30
  29. 33
  30. 80
  31. 30
  32. Well done, Meera!
  33. 108
  34. 40
  35. Hi, Kabir!
  36. 40
  37. 120
  38. 70
  39. 130
  40. 60

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