← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 70
  2. 117
  3. 38
  4. Well done, Kabir!
  5. Hi, Riya!
  6. 18
  7. sends back a value
  8. 60
  9. to reuse code
  10. 30
  11. 36
  12. 100
  13. a named block of code
  14. 340
  15. Well done, Meera!
  16. greet()
  17. 40
  18. 42
  19. 50
  20. a parameter
  21. 360
  22. 60
  23. 60
  24. Hi, Zoya!
  25. 40
  26. Welcome, Arjun!
  27. 42
  28. 275
  29. 18
  30. 60
  31. 0
  32. 111
  33. 84
  34. 175
  35. 90
  36. 50
  37. 500
  38. 70
  39. 30
  40. Hello, Zoya!

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