I’m practicing simple JS functions but don’t understand why this function doesn’t return area
:
function rectangleArea(width, height) {
let area = width * height;
return area;
}
rectangleArea(5, 7)
I’m practicing simple JS functions but don’t understand why this function doesn’t return area
:
function rectangleArea(width, height) {
let area = width * height;
return area;
}
rectangleArea(5, 7)
Just tested it, it works fine. Maybe show more of you code?
@M-Michelini Thanks. That’s all the code. I have it in Codepen and when I click “run”, it produces nothing- neither an output nor an error. It should log to the console right? (it’s not logging to the console or the page)
you want console.log(rectangleArea(5, 7))
Ok so the return function does not actually log to the console on its own?
That’s right, except return is a keyword not a function.
You are correct, the return function is going to stop the function from executing and return a value from that function but it doesn’t log anything to the console.