← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 60
  2. 20
  3. 100
  4. 70
  5. 375
  6. 78
  7. 300
  8. to reuse code
  9. a named block of code
  10. 80
  11. 280
  12. 270
  13. a parameter
  14. Hello, Aman!
  15. 100
  16. Welcome, Zoya!
  17. 80
  18. sends back a value
  19. 93
  20. 40
  21. 325
  22. Hello, Zoya!
  23. greet()
  24. 90
  25. 90
  26. 108
  27. 28
  28. Hi, Aman!
  29. 100
  30. Hello, Meera!
  31. 30
  32. 70
  33. 240
  34. 0
  35. 225
  36. 60
  37. 66
  38. Hi, Kabir!
  39. Hello, Riya!
  40. 60

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