← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 60
  2. 425
  3. a parameter
  4. 300
  5. to reuse code
  6. 100
  7. sends back a value
  8. 420
  9. Well done, Riya!
  10. 42
  11. 20
  12. 30
  13. 220
  14. 40
  15. 150
  16. Hello, Riya!
  17. Hello, Meera!
  18. 120
  19. 60
  20. Hello, Kabir!
  21. 60
  22. 117
  23. Well done, Arjun!
  24. 78
  25. 90
  26. 10
  27. greet()
  28. 0
  29. 50
  30. 66
  31. 70
  32. 390
  33. 40
  34. 30
  35. a named block of code
  36. 20
  37. 170
  38. 60
  39. 26
  40. 72

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