← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 90
  2. 80
  3. 50
  4. Well done, Aman!
  5. a parameter
  6. 80
  7. a named block of code
  8. 90
  9. Hello, Zoya!
  10. 40
  11. Hi, Aman!
  12. Welcome, Riya!
  13. 0
  14. sends back a value
  15. Welcome, Zoya!
  16. 40
  17. 24
  18. 110
  19. greet()
  20. 60
  21. 74
  22. 18
  23. Hi, Meera!
  24. 60
  25. 18
  26. Hi, Riya!
  27. 78
  28. 260
  29. 60
  30. 390
  31. 80
  32. 30
  33. 50
  34. 30
  35. 20
  36. 30
  37. 75
  38. 170
  39. 96
  40. 120

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