← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. sends back a value
  2. a parameter
  3. 40
  4. 33
  5. greet()
  6. Hi, Kabir!
  7. 38
  8. Hello, Arjun!
  9. a named block of code
  10. 120
  11. 80
  12. 600
  13. Welcome, Aman!
  14. 20
  15. 93
  16. 96
  17. 70
  18. 80
  19. 360
  20. Hello, Zoya!
  21. 30
  22. 20
  23. 100
  24. 50
  25. 270
  26. 36
  27. 60
  28. 200
  29. Hi, Meera!
  30. Hello, Kabir!
  31. 42
  32. 74
  33. 70
  34. 240
  35. 125
  36. 26
  37. 70
  38. to reuse code
  39. 100
  40. 50

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