Ajax-loader-large-white
Loops in JavaScript
Return of the "return"

Recall that a function is something like a named block of code that we can easily call again later. Optionally associated with each function is a return statement. A return statement is what a function "gives back" after it is called. The value returned can be assigned to a variable.

Suppose that the function totalPrice of a car object calculates the total price for a car and returns this price. If the total price ends up being $20,000, then the myPrice variable in the following statement will be 20000.

var myPrice = car.totalPrice();

The return keyword is not a variable. Remember that it is a keyword that simply spits out what you want it to spit back out.

Instructions

Finish the supplied add function. It should sum up the arguments number1, number2, and number3 into the variable sum. Then you should return the sum.

After the function definition, call add twice: once using 1, 2, and 3 as arguments, and again using 10, 10, and -20 as arguments. Assign the values that these function calls return to new variables sum1 and sum2, respectively.

?
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Remember what return statements look like:

return someVar;

Also remember how we assign the value of a return statement to another variable:

var anotherVar = myFunction(parameter);

script.js