← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. 30
  2. Well done, Riya!
  3. 114
  4. 30
  5. 60
  6. 240
  7. Hi, Arjun!
  8. 40
  9. 400
  10. sends back a value
  11. 36
  12. 100
  13. a parameter
  14. 66
  15. to reuse code
  16. Well done, Aman!
  17. 20
  18. 190
  19. 52
  20. 20
  21. 60
  22. 20
  23. Hello, Riya!
  24. 105
  25. 80
  26. 70
  27. 45
  28. 50
  29. 60
  30. 140
  31. greet()
  32. 125
  33. 30
  34. Welcome, Riya!
  35. 51
  36. 40
  37. 70
  38. 30
  39. 111
  40. 510

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