← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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