← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Welcome, Aman!
  2. a parameter
  3. 180
  4. 0
  5. to reuse code
  6. 42
  7. 30
  8. 160
  9. 475
  10. Welcome, Zoya!
  11. a named block of code
  12. 80
  13. 40
  14. Well done, Arjun!
  15. 69
  16. 36
  17. greet()
  18. 20
  19. 54
  20. Welcome, Meera!
  21. 62
  22. 15
  23. 30
  24. Hi, Kabir!
  25. 114
  26. 90
  27. 100
  28. 110
  29. 60
  30. 60
  31. 111
  32. 135
  33. 285
  34. 165
  35. 120
  36. 350
  37. 60
  38. sends back a value
  39. 570
  40. Hello, Kabir!

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