← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 27
  2. greet()
  3. Hello, Aman!
  4. 0
  5. 350
  6. 300
  7. Welcome, Aman!
  8. 38
  9. 40
  10. a parameter
  11. Well done, Arjun!
  12. 62
  13. 70
  14. 102
  15. 21
  16. Hi, Arjun!
  17. 40
  18. 78
  19. 110
  20. 60
  21. Welcome, Riya!
  22. 40
  23. 200
  24. 195
  25. 18
  26. 40
  27. to reuse code
  28. 135
  29. 0
  30. 48
  31. 60
  32. 80
  33. sends back a value
  34. 32
  35. 100
  36. a named block of code
  37. 24
  38. 60
  39. 200
  40. 70

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