← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 36
  2. greet()
  3. 50
  4. sends back a value
  5. a parameter
  6. Hi, Aman!
  7. 117
  8. 76
  9. 330
  10. to reuse code
  11. Welcome, Riya!
  12. Hi, Meera!
  13. 70
  14. 44
  15. a named block of code
  16. 600
  17. 54
  18. Well done, Meera!
  19. 60
  20. 96
  21. 100
  22. 111
  23. 46
  24. 87
  25. 33
  26. 30
  27. 30
  28. 50
  29. 90
  30. 120
  31. 15
  32. 140
  33. 20
  34. Hello, Riya!
  35. Hello, Zoya!
  36. 60
  37. 24
  38. Well done, Arjun!
  39. 120
  40. 0

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