← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a parameter
  2. Welcome, Riya!
  3. 165
  4. 70
  5. 32
  6. 320
  7. 30
  8. 60
  9. 100
  10. sends back a value
  11. 120
  12. 120
  13. 45
  14. 76
  15. 40
  16. 28
  17. 100
  18. 60
  19. 40
  20. to reuse code
  21. Hello, Meera!
  22. 70
  23. 40
  24. 100
  25. Well done, Meera!
  26. 0
  27. Hello, Zoya!
  28. 20
  29. a named block of code
  30. 46
  31. 57
  32. 60
  33. Well done, Riya!
  34. 20
  35. Welcome, Meera!
  36. 40
  37. Hi, Meera!
  38. greet()
  39. 50
  40. 58

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