← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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