← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. greet()
  2. 150
  3. 320
  4. 510
  5. 90
  6. 450
  7. 78
  8. 80
  9. 140
  10. 60
  11. 80
  12. sends back a value
  13. Well done, Kabir!
  14. Hello, Arjun!
  15. a parameter
  16. Welcome, Riya!
  17. 80
  18. 170
  19. 60
  20. 16
  21. 10
  22. 150
  23. 100
  24. 105
  25. 38
  26. 50
  27. 110
  28. a named block of code
  29. 60
  30. 27
  31. 30
  32. 120
  33. 80
  34. to reuse code
  35. 165
  36. 390
  37. 60
  38. 60
  39. Welcome, Zoya!
  40. 225

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