← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. a named block of code
  2. Well done, Riya!
  3. Hello, Riya!
  4. 100
  5. 140
  6. 50
  7. 160
  8. Hello, Aman!
  9. Welcome, Arjun!
  10. 16
  11. to reuse code
  12. 40
  13. 20
  14. 60
  15. 425
  16. sends back a value
  17. 32
  18. a parameter
  19. greet()
  20. 62
  21. 60
  22. Hi, Riya!
  23. Welcome, Kabir!
  24. 240
  25. 50
  26. 195
  27. 36
  28. 14
  29. 380
  30. 120
  31. Well done, Kabir!
  32. 60
  33. 6
  34. 30
  35. 80
  36. Hello, Arjun!
  37. 570
  38. Well done, Arjun!
  39. 30
  40. 240

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