← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a parameter
  2. 150
  3. 80
  4. 70
  5. 200
  6. 72
  7. 75
  8. 200
  9. 570
  10. sends back a value
  11. 48
  12. greet()
  13. 32
  14. 6
  15. 540
  16. 40
  17. Well done, Meera!
  18. 60
  19. to reuse code
  20. 100
  21. Well done, Zoya!
  22. 60
  23. 56
  24. 26
  25. 70
  26. Hello, Zoya!
  27. 20
  28. 105
  29. Hello, Arjun!
  30. 80
  31. 18
  32. a named block of code
  33. Welcome, Zoya!
  34. Well done, Arjun!
  35. 80
  36. 400
  37. Hi, Arjun!
  38. 48
  39. 40
  40. 165

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