← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a parameter
  2. Hello, Aman!
  3. Hi, Arjun!
  4. 135
  5. Welcome, Kabir!
  6. 50
  7. 60
  8. Hello, Meera!
  9. 50
  10. 30
  11. greet()
  12. to reuse code
  13. 20
  14. 80
  15. 70
  16. 60
  17. 40
  18. 350
  19. a named block of code
  20. 110
  21. 60
  22. 40
  23. sends back a value
  24. 28
  25. 24
  26. Hello, Zoya!
  27. 240
  28. 38
  29. 81
  30. 84
  31. 160
  32. 75
  33. 50
  34. 50
  35. 30
  36. 180
  37. 100
  38. Hi, Kabir!
  39. 60
  40. 20

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