← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

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

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