← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Well done, Zoya!
  2. 50
  3. 60
  4. a named block of code
  5. 18
  6. to reuse code
  7. 100
  8. Hi, Arjun!
  9. 120
  10. a parameter
  11. 50
  12. 30
  13. 30
  14. Welcome, Aman!
  15. greet()
  16. Well done, Meera!
  17. 33
  18. 96
  19. 30
  20. 255
  21. 110
  22. Hi, Aman!
  23. 40
  24. 14
  25. 8
  26. 350
  27. 50
  28. 44
  29. 48
  30. 60
  31. 40
  32. 50
  33. 80
  34. 0
  35. 30
  36. 50
  37. Well done, Aman!
  38. 20
  39. 80
  40. 78

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