← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Welcome, Riya!
  2. 60
  3. 70
  4. 24
  5. 360
  6. 70
  7. Welcome, Kabir!
  8. 20
  9. Hello, Kabir!
  10. 0
  11. Welcome, Meera!
  12. 78
  13. 34
  14. Well done, Zoya!
  15. 60
  16. 90
  17. 190
  18. 100
  19. Hi, Aman!
  20. 50
  21. 330
  22. to reuse code
  23. 87
  24. sends back a value
  25. 30
  26. Hi, Arjun!
  27. 80
  28. Welcome, Aman!
  29. 30
  30. 500
  31. 72
  32. 30
  33. a parameter
  34. Well done, Riya!
  35. 400
  36. 6
  37. 50
  38. a named block of code
  39. 74
  40. 30

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