← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 225
  2. 20
  3. 320
  4. Hi, Meera!
  5. greet()
  6. 70
  7. 68
  8. 360
  9. 20
  10. 16
  11. 180
  12. a parameter
  13. 40
  14. 58
  15. 100
  16. 64
  17. 40
  18. 40
  19. Well done, Riya!
  20. 30
  21. 84
  22. 130
  23. 210
  24. sends back a value
  25. Well done, Meera!
  26. 60
  27. 108
  28. 0
  29. 51
  30. Hi, Zoya!
  31. 24
  32. 50
  33. a named block of code
  34. 60
  35. 10
  36. Well done, Aman!
  37. 50
  38. 22
  39. 70
  40. 80

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