← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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