← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 81
  2. 150
  3. 175
  4. sends back a value
  5. 100
  6. greet()
  7. 20
  8. 60
  9. Welcome, Zoya!
  10. 50
  11. a parameter
  12. 40
  13. 120
  14. a named block of code
  15. 150
  16. 52
  17. Hi, Zoya!
  18. 80
  19. 120
  20. to reuse code
  21. 54
  22. 60
  23. 60
  24. 100
  25. Well done, Arjun!
  26. 80
  27. 30
  28. Hi, Aman!
  29. Hi, Kabir!
  30. 6
  31. 15
  32. Hello, Riya!
  33. 30
  34. 36
  35. 0
  36. 30
  37. 60
  38. 8
  39. 60
  40. 60

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