← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Hi, Meera!
  2. a parameter
  3. 90
  4. 90
  5. greet()
  6. 300
  7. Hello, Arjun!
  8. a named block of code
  9. 87
  10. 42
  11. 80
  12. 40
  13. to reuse code
  14. 18
  15. sends back a value
  16. 60
  17. 400
  18. 390
  19. 36
  20. 450
  21. 50
  22. Welcome, Zoya!
  23. 50
  24. 8
  25. 20
  26. 80
  27. Hello, Kabir!
  28. 110
  29. 120
  30. Well done, Aman!
  31. 80
  32. 225
  33. Hello, Meera!
  34. 70
  35. 14
  36. 60
  37. 45
  38. 425
  39. 40
  40. 30

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