← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 40
  2. Well done, Kabir!
  3. 84
  4. 180
  5. 60
  6. Hello, Riya!
  7. a parameter
  8. 360
  9. to reuse code
  10. sends back a value
  11. 80
  12. Well done, Riya!
  13. Hi, Arjun!
  14. 20
  15. 72
  16. 72
  17. 90
  18. 50
  19. 50
  20. a named block of code
  21. 54
  22. Well done, Arjun!
  23. 20
  24. 102
  25. 52
  26. 111
  27. 42
  28. 38
  29. 51
  30. 78
  31. 50
  32. Hello, Arjun!
  33. 40
  34. 195
  35. 70
  36. 22
  37. 200
  38. 90
  39. 60
  40. greet()

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