← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Welcome, Zoya!
  2. Welcome, Riya!
  3. 60
  4. 180
  5. 14
  6. 40
  7. Hi, Riya!
  8. Hi, Kabir!
  9. a named block of code
  10. a parameter
  11. 72
  12. 0
  13. 60
  14. 375
  15. to reuse code
  16. 40
  17. 240
  18. 50
  19. 38
  20. 64
  21. Hi, Aman!
  22. 60
  23. 60
  24. 81
  25. Hello, Arjun!
  26. 52
  27. 150
  28. 225
  29. 36
  30. sends back a value
  31. 200
  32. 210
  33. 60
  34. Hello, Aman!
  35. 105
  36. 190
  37. 30
  38. 24
  39. 56
  40. 32

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