← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 50
  2. 90
  3. Hello, Riya!
  4. 280
  5. greet()
  6. 70
  7. Hello, Meera!
  8. 0
  9. to reuse code
  10. 570
  11. 80
  12. 28
  13. 50
  14. 100
  15. Hello, Arjun!
  16. 30
  17. Hello, Kabir!
  18. sends back a value
  19. 125
  20. 90
  21. 300
  22. 75
  23. 120
  24. 70
  25. 87
  26. 90
  27. 20
  28. 60
  29. 60
  30. 150
  31. Welcome, Kabir!
  32. 500
  33. 80
  34. 30
  35. 40
  36. 50
  37. 22
  38. Hi, Zoya!
  39. 9
  40. a named block of code

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