← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Hello, Arjun!
  2. Well done, Aman!
  3. a named block of code
  4. Welcome, Kabir!
  5. greet()
  6. 58
  7. 200
  8. 44
  9. 75
  10. sends back a value
  11. 190
  12. 100
  13. 60
  14. 120
  15. 20
  16. 220
  17. 60
  18. 375
  19. to reuse code
  20. 34
  21. 50
  22. Well done, Riya!
  23. 114
  24. 64
  25. 90
  26. Well done, Meera!
  27. 60
  28. 60
  29. Hello, Kabir!
  30. 30
  31. 175
  32. 39
  33. 420
  34. 56
  35. 40
  36. 120
  37. 80
  38. 36
  39. 20
  40. a parameter

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