← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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