Aim of the puzzle: Write a function that returns the product of 2 numbers.
Walk through of solution: The code contains a function called sum
that returns the sum of 2 numbers. In this puzzle, you’ll create another function that returns the product of 2 numbers.
To complete this puzzle, create a function called product
. Inside the parentheses ()
of the product
function declaration, insert num1
and num2
. Then, inside the code block {}
of the product
function declaration, add return num1 * num2
. Finally, below the function declaration, use console.log()
to print product(4,5)
.
This is the first time you need to type out an entire function declaration on your own, so don’t forget to type:
- The
function
keyword - The name of the function,
product
- The parameters,
num1
andnum2
, inside the parentheses()
- The return statement,
return num1 * num2
, inside the code block{}
Sample code solution:
function sum(num1, num2) {
return num1 + num2;
}
console.log(sum(2,3));
function product(num1, num2) {
return num1 * num2;
}
console.log(product(4,5));
Javascript Concepts: functions, parameters, return statement, console.log()