← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 50
  2. 60
  3. 425
  4. Well done, Kabir!
  5. Hello, Riya!
  6. 100
  7. Welcome, Aman!
  8. 50
  9. 40
  10. Well done, Zoya!
  11. 100
  12. a parameter
  13. 220
  14. 60
  15. greet()
  16. 320
  17. 450
  18. 117
  19. 70
  20. sends back a value
  21. 40
  22. 80
  23. 54
  24. 78
  25. 100
  26. 50
  27. 26
  28. to reuse code
  29. 360
  30. 255
  31. 340
  32. 30
  33. a named block of code
  34. Well done, Aman!
  35. 9
  36. 50
  37. Hi, Kabir!
  38. 285
  39. 21
  40. 120

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