← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Well done, Kabir!
  2. Welcome, Zoya!
  3. 64
  4. Welcome, Riya!
  5. Welcome, Kabir!
  6. 40
  7. 90
  8. 90
  9. sends back a value
  10. Hello, Zoya!
  11. 20
  12. 400
  13. 100
  14. 18
  15. 80
  16. 135
  17. Hi, Zoya!
  18. 60
  19. to reuse code
  20. 80
  21. 90
  22. 570
  23. 14
  24. 60
  25. 100
  26. greet()
  27. 50
  28. 30
  29. a named block of code
  30. 24
  31. 110
  32. 70
  33. 125
  34. 117
  35. 90
  36. 9
  37. 420
  38. 93
  39. 54
  40. 20

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