← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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