← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Well done, Aman!
  2. 12
  3. 40
  4. 80
  5. Welcome, Zoya!
  6. 60
  7. 340
  8. a named block of code
  9. 18
  10. 180
  11. 20
  12. 48
  13. 120
  14. 36
  15. 24
  16. Hello, Kabir!
  17. Hi, Aman!
  18. 20
  19. 81
  20. sends back a value
  21. 60
  22. Hi, Riya!
  23. 50
  24. 270
  25. 27
  26. 72
  27. 600
  28. greet()
  29. Hi, Meera!
  30. 20
  31. 21
  32. 50
  33. 54
  34. 66
  35. 210
  36. 180
  37. Hello, Riya!
  38. 60
  39. 285
  40. 26

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