← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Hi, Arjun!
  2. a parameter
  3. 26
  4. 54
  5. sends back a value
  6. 74
  7. 80
  8. 40
  9. Hi, Zoya!
  10. 150
  11. Welcome, Meera!
  12. 60
  13. greet()
  14. 60
  15. to reuse code
  16. 99
  17. 40
  18. 58
  19. 120
  20. 60
  21. a named block of code
  22. Hello, Zoya!
  23. 480
  24. 90
  25. 32
  26. 275
  27. 50
  28. 450
  29. 200
  30. 20
  31. 40
  32. 70
  33. 40
  34. 60
  35. 30
  36. 78
  37. 40
  38. 30
  39. 80
  40. 20

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