← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 30
  2. Hello, Riya!
  3. 12
  4. 40
  5. a parameter
  6. 100
  7. a named block of code
  8. sends back a value
  9. 72
  10. Hi, Kabir!
  11. 60
  12. Hi, Meera!
  13. 540
  14. 20
  15. 48
  16. Hi, Riya!
  17. 40
  18. 225
  19. 120
  20. 105
  21. 285
  22. greet()
  23. 80
  24. 40
  25. Hello, Arjun!
  26. 42
  27. 56
  28. 32
  29. 330
  30. Well done, Aman!
  31. 74
  32. 390
  33. 42
  34. 90
  35. 70
  36. 20
  37. 16
  38. 60
  39. 27
  40. 114

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