← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Hello, Zoya!
  2. greet()
  3. Hello, Meera!
  4. Hi, Zoya!
  5. Hello, Riya!
  6. Welcome, Aman!
  7. Hello, Kabir!
  8. 15
  9. 180
  10. a named block of code
  11. sends back a value
  12. 20
  13. Well done, Arjun!
  14. 300
  15. 90
  16. 60
  17. Hi, Aman!
  18. 9
  19. 58
  20. 38
  21. 30
  22. 0
  23. 90
  24. 54
  25. 425
  26. 64
  27. 210
  28. 74
  29. Welcome, Kabir!
  30. 40
  31. 50
  32. 120
  33. 78
  34. 300
  35. 30
  36. 60
  37. Hello, Aman!
  38. a parameter
  39. 50
  40. Hi, Riya!

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