← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a parameter
  2. 56
  3. 30
  4. 20
  5. Hi, Riya!
  6. 42
  7. 100
  8. 20
  9. 175
  10. 60
  11. 60
  12. Hello, Arjun!
  13. Well done, Arjun!
  14. greet()
  15. 20
  16. 34
  17. 80
  18. Hi, Aman!
  19. 120
  20. sends back a value
  21. 90
  22. 6
  23. 51
  24. 100
  25. 40
  26. to reuse code
  27. 80
  28. 54
  29. 80
  30. 390
  31. 450
  32. 120
  33. 50
  34. 32
  35. a named block of code
  36. 69
  37. 30
  38. Well done, Kabir!
  39. Well done, Aman!
  40. 60

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