← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 80
  2. 260
  3. 0
  4. Well done, Riya!
  5. 360
  6. 40
  7. 30
  8. Well done, Meera!
  9. 30
  10. 50
  11. 60
  12. Welcome, Riya!
  13. 66
  14. to reuse code
  15. 300
  16. 150
  17. 210
  18. 80
  19. 90
  20. a named block of code
  21. 80
  22. 70
  23. a parameter
  24. 90
  25. Hello, Riya!
  26. 60
  27. 20
  28. sends back a value
  29. 42
  30. 240
  31. 60
  32. Welcome, Meera!
  33. 40
  34. 12
  35. Hello, Aman!
  36. greet()
  37. 33
  38. 300
  39. 350
  40. 100

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