Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSarah Breidenbach
4,490 PointsThe way I solved this did not require the return keyword and I would like clarifications as to why
// a function that calculates the area of a rectangle.
function calculateRectangle (width, height) {
rectangleArea = width * height;
console.log(rectangleArea);
}
calculateRectangle(5, 22);
1 Answer
Steven Parker
231,269 PointsSome functions do something, and some return something, and some may do both. This is an example of a function that doesn't return anything. Instead, it does something and displays the result directly on the console.
But let's say you were to call the function like this:
var answer = calculateRectangle(5, 22);
After that runs, the value of "answer" would be "undefined", because nothing was returned. But it would still display "110" on the console while it was running.