← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 300
  2. 45
  3. Well done, Zoya!
  4. 110
  5. 40
  6. 600
  7. a named block of code
  8. 76
  9. 120
  10. sends back a value
  11. 50
  12. a parameter
  13. 30
  14. 375
  15. 80
  16. 100
  17. 360
  18. greet()
  19. 40
  20. 60
  21. 200
  22. 54
  23. 100
  24. 80
  25. 20
  26. 180
  27. 90
  28. 56
  29. 30
  30. 74
  31. Hello, Aman!
  32. 8
  33. to reuse code
  34. Well done, Aman!
  35. 60
  36. 50
  37. 30
  38. Welcome, Meera!
  39. 60
  40. Welcome, Riya!

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