← Functions lesson New set →

App Dev Worksheet: Functions

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

Answer key

  1. Welcome, Meera!
  2. 195
  3. Hello, Kabir!
  4. 54
  5. greet()
  6. a named block of code
  7. 280
  8. 60
  9. 50
  10. 60
  11. 120
  12. 40
  13. 100
  14. a parameter
  15. 70
  16. Hello, Zoya!
  17. Hi, Zoya!
  18. 33
  19. 390
  20. 12
  21. sends back a value
  22. Welcome, Riya!
  23. Welcome, Arjun!
  24. 0
  25. Hello, Riya!
  26. 20
  27. 120
  28. 26
  29. 40
  30. 150
  31. 120
  32. 100
  33. 50
  34. 250
  35. 40
  36. 80
  37. 74
  38. 120
  39. 60
  40. 80

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