← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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