Functions – Return Values

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Functions – Return Values

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does return send a value back out of a function?
A Yes
B No
2. Does return end the function's execution at that point?
A Yes
B No
3. Can a returned value be stored in a variable?
A Yes
B No
4. Must 'return' be written in lowercase?
A No
B Yes
5. Is 'retrun' a valid spelling of the keyword?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1return a + b; AStores the value returned by add() in total
2let total = add(2, 3); BWrong - 'return' must be lowercase
3Ends a function's execution and sends back a value Creturn
4Sends back the square of a number DSends the sum of a and b back out of the function
5Retrun a + b; EWrong - 'return' is misspelled
6Return a - b; Freturn n * n;

Definitions

return

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ a + b;
2.
let total _ add(2, 3);
3.
______ x * y;
4.
function square(n) { ______ n * n; }
5.
let result _ square(4);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A function add(a, b) {
B Return a + b;
C }
Question 2
A function sub(a, b) {
B retrun a - b;
C }
Question 3
A console.log("mult");
B function mult(x, y) {
C return x * y
D }
Question 4
A function square(n) {
B return n * n;
C ]
Question 5
A function greet() {
B return "Hi";
C }
D let msg = greet()

Answer Key

Functions – Return Values
Section A: Quick Questions
Q1
A — Yes
Q2
A — Yes
Q3
A — Yes
Q4
B — Yes
Q5
B — No
Section B: Match the Pairs
Q1
return a + b; → Sends the sum of a and b back out of the function
Q2
let total = add(2, 3); → Stores the value returned by add() in total
Q3
Ends a function's execution and sends back a value → return
Q4
Sends back the square of a number → return n * n;
Q5
Retrun a + b; → Wrong - 'return' is misspelled
Q6
Return a - b; → Wrong - 'return' must be lowercase
Section C: Definitions
Q1
return — Sends a value back out of a function and ends its execution at that point.
Section D: Fill in the Blanks
Q1
return a + b;
Q2
let total = add(2, 3);
Q3
return x * y;
Q4
function square(n) { return n * n; }
Q5
let result = square(4);
Section E: Spot the Error
Q1
B — 'return' must be lowercase - a capital R causes an error.
Q2
B — 'return' is misspelled as 'retrun'.
Q3
C — This line is missing a semicolon, but that's not required in JS.
Q4
C — The block must close with }, not ].
Q5
D — This line is missing a semicolon, but that's not required in JS.