← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 30
  2. Welcome, Arjun!
  3. 20
  4. 0
  5. 40
  6. 320
  7. 40
  8. Hello, Aman!
  9. 90
  10. 50
  11. 180
  12. sends back a value
  13. 62
  14. 75
  15. 42
  16. 540
  17. 200
  18. a parameter
  19. 20
  20. to reuse code
  21. 200
  22. 81
  23. 105
  24. 96
  25. greet()
  26. 70
  27. 27
  28. 420
  29. 30
  30. Hello, Riya!
  31. 12
  32. 90
  33. 80
  34. 225
  35. 70
  36. 33
  37. 475
  38. 8
  39. 40
  40. 60

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