← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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