← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 150
  2. 78
  3. 70
  4. 360
  5. Hi, Riya!
  6. 420
  7. Hi, Meera!
  8. greet()
  9. Welcome, Kabir!
  10. Well done, Zoya!
  11. 80
  12. 81
  13. 60
  14. 87
  15. Well done, Meera!
  16. 30
  17. 80
  18. to reuse code
  19. 90
  20. 70
  21. 285
  22. 140
  23. 30
  24. 93
  25. 70
  26. 30
  27. 120
  28. 60
  29. 28
  30. 30
  31. Well done, Aman!
  32. sends back a value
  33. a named block of code
  34. 10
  35. Welcome, Aman!
  36. 90
  37. 60
  38. Hello, Meera!
  39. 100
  40. 105

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