← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 80
  2. 450
  3. 58
  4. 75
  5. Hello, Zoya!
  6. a named block of code
  7. 500
  8. Hello, Riya!
  9. 110
  10. 30
  11. 105
  12. 60
  13. 90
  14. Well done, Zoya!
  15. 14
  16. 60
  17. 275
  18. 34
  19. 76
  20. 22
  21. 100
  22. Hello, Meera!
  23. 27
  24. a parameter
  25. 70
  26. greet()
  27. 60
  28. 60
  29. 100
  30. 100
  31. sends back a value
  32. 160
  33. 100
  34. Hi, Arjun!
  35. Welcome, Zoya!
  36. 50
  37. 510
  38. 66
  39. 30
  40. 36

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