← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Hello, Zoya!
  2. 90
  3. 0
  4. 400
  5. 175
  6. 66
  7. 120
  8. 72
  9. sends back a value
  10. 360
  11. 50
  12. 60
  13. 80
  14. 80
  15. 0
  16. a parameter
  17. 75
  18. Well done, Meera!
  19. 100
  20. a named block of code
  21. 45
  22. 45
  23. Hello, Riya!
  24. 50
  25. 40
  26. 40
  27. greet()
  28. 30
  29. 32
  30. 330
  31. 70
  32. 58
  33. to reuse code
  34. 80
  35. 30
  36. 100
  37. Well done, Kabir!
  38. 12
  39. 120
  40. Hello, Meera!

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