← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 72
  2. a named block of code
  3. 100
  4. 285
  5. 50
  6. 30
  7. 50
  8. 40
  9. 80
  10. 40
  11. 33
  12. 160
  13. greet()
  14. 80
  15. Hello, Meera!
  16. 150
  17. Welcome, Aman!
  18. 90
  19. 40
  20. 70
  21. 40
  22. 20
  23. 220
  24. Hello, Kabir!
  25. 50
  26. 150
  27. 120
  28. Hello, Aman!
  29. 51
  30. 60
  31. 240
  32. 20
  33. Well done, Arjun!
  34. 15
  35. 120
  36. 30
  37. sends back a value
  38. 40
  39. 200
  40. 60

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