← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 40
  2. greet()
  3. sends back a value
  4. 36
  5. Welcome, Aman!
  6. 20
  7. 80
  8. 500
  9. a parameter
  10. Hi, Riya!
  11. a named block of code
  12. 64
  13. 62
  14. 60
  15. 60
  16. 40
  17. 20
  18. 80
  19. Welcome, Kabir!
  20. 100
  21. 60
  22. 30
  23. 390
  24. 114
  25. 80
  26. Hello, Riya!
  27. 70
  28. 0
  29. to reuse code
  30. 40
  31. 60
  32. 76
  33. Well done, Aman!
  34. 8
  35. 120
  36. Hello, Meera!
  37. 400
  38. 78
  39. 80
  40. Well done, Riya!

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