← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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