← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. to reuse code
  2. sends back a value
  3. 100
  4. 120
  5. Welcome, Arjun!
  6. 81
  7. Hello, Zoya!
  8. 100
  9. 390
  10. a named block of code
  11. Well done, Aman!
  12. 40
  13. 175
  14. 80
  15. Well done, Meera!
  16. a parameter
  17. 210
  18. 200
  19. Hi, Arjun!
  20. 50
  21. 170
  22. 96
  23. 200
  24. 60
  25. 420
  26. Hello, Meera!
  27. 38
  28. 100
  29. Hi, Riya!
  30. 195
  31. Hello, Riya!
  32. 30
  33. 30
  34. 255
  35. greet()
  36. 8
  37. 66
  38. 46
  39. Hi, Kabir!
  40. 52

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