← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 80
  2. 20
  3. 120
  4. 108
  5. 260
  6. Welcome, Riya!
  7. Well done, Arjun!
  8. 12
  9. 360
  10. a parameter
  11. Hello, Aman!
  12. 48
  13. 72
  14. 60
  15. 80
  16. 70
  17. 60
  18. 300
  19. 120
  20. 12
  21. 8
  22. 114
  23. greet()
  24. sends back a value
  25. 50
  26. a named block of code
  27. 40
  28. 30
  29. 120
  30. 60
  31. 30
  32. Welcome, Aman!
  33. 40
  34. 21
  35. to reuse code
  36. 30
  37. 280
  38. 120
  39. 275
  40. Well done, Zoya!

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