← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 160
  2. Welcome, Zoya!
  3. Welcome, Riya!
  4. 20
  5. 70
  6. a named block of code
  7. Hi, Riya!
  8. 325
  9. 45
  10. 360
  11. 90
  12. 40
  13. to reuse code
  14. 50
  15. 70
  16. 24
  17. 60
  18. a parameter
  19. Hello, Aman!
  20. 60
  21. 14
  22. Hi, Zoya!
  23. 380
  24. 60
  25. 30
  26. greet()
  27. 20
  28. 50
  29. 80
  30. 6
  31. 75
  32. 120
  33. 30
  34. sends back a value
  35. 40
  36. 50
  37. 0
  38. Well done, Meera!
  39. 50
  40. 285

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