← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 117
  2. 60
  3. 27
  4. 110
  5. 20
  6. 280
  7. 80
  8. Hi, Arjun!
  9. sends back a value
  10. 120
  11. 60
  12. 360
  13. to reuse code
  14. 30
  15. 70
  16. 40
  17. 60
  18. 15
  19. Well done, Aman!
  20. Hello, Aman!
  21. 100
  22. 50
  23. 30
  24. a parameter
  25. Hello, Zoya!
  26. 220
  27. 34
  28. 60
  29. 42
  30. 26
  31. 30
  32. 45
  33. greet()
  34. 80
  35. 78
  36. 90
  37. 78
  38. 60
  39. 180
  40. 40

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