Functions – Return Values, online
Six activities your students do on their own devices. See who's finished, and their scores.
Functions – Return Values in one minute
What students need to know
return is exactly the keyword that does this. This multiplies n by itself and returns the result.
return hands the value back to wherever the function was called. Once return runs, no more code in the function executes.
Mistakes students make
- 'return' must be lowercase - a capital R causes an error.
- 'return' is misspelled as 'retrun'.
- This line is missing a semicolon, but that's not required in JS.
- The block must close with }, not ].
What students will learn in this module
Every question in Module 40
Quick questions
- Does return send a value back out of a function?AYesBNo
- Does return end the function's execution at that point?AYesBNo
- Can a returned value be stored in a variable?AYesBNo
- Must 'return' be written in lowercase?ANoBYes
- Is 'retrun' a valid spelling of the keyword?AYesBNo
Key terms
Students type the meaning of:
return
Match the pairs
return a + b;Match it to what it doeslet total = add(2, 3);Match it to what it doesEnds a function's execution and sends back a valueMatch it to what it doesSends back the square of a numberMatch it to what it doesRetrun a + b;Match it to what it doesReturn a - b;Match it to what it doesFill in the blanks
______ a + b;
Hint: Type the keyword that sends a value back from the function.
let total _ add(2, 3);
Hint: Type the symbol used to assign the returned value to total.
______ x * y;
Hint: Type the keyword that sends a value back from the function.
function square(n) { ______ n * n; }Hint: Type the keyword that sends a value back from the function.
let result _ square(4);
Hint: Type the symbol used to assign the returned value to result.
Spot the error
Question 1
Afunction add(a, b) {BReturn a + b;C}
Question 2
Afunction sub(a, b) {Bretrun a - b;C}
Question 3
Aconsole.log("mult");Bfunction mult(x, y) {Creturn x * yD}
Question 4
Afunction square(n) {Breturn n * n;C]
Question 5
Afunction greet() {Breturn "Hi";C}Dlet msg = greet()
