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 trial

JavaScript JavaScript Functions Pass Information Into Functions Pass Multiple Arguments to a Function

My code from the workspace is not computing in my console.

This...

function getArea(width, length, unit) { const area = width * length; return '${area} ${unit}'; }

...should make this...

getArea (10, 20, 'sq ft');

...create this in the console...

200 sq ft

...but doesn't... What should I do?

2 Answers

Lachlan Stevens
Lachlan Stevens
10,779 Points

Two issues with your code.

  1. It isn't outputting to the console because you haven't told it to do so. All "return" does is pass the value back out of a function. To output something to the console you would need to use console.log.

  2. Once you're past that, you have used single quotes to wrap your return ( ' ). You're trying to use template literals, which you will need to use backticks ( ` - on the same key as the tilde (~) in most layouts).

Hope this helps!

for the code to work you should right you code like this; everything is correct apart from when you r returning the function. for it to return what your suggesting your code should be like this; first declare a variable to store the return function like; const finalAnswer = ${area} ${unit}; then return the value of finalAnswer in your function like this return finalAnswer; this should work perfectly lastly call the function like this; console.log( getArea(width,length,'sqt ft);

Steven Parker
Steven Parker
229,771 Points

This function only creates a string and returns it to the code that called it, it does not display it on the console.

Displaying it is probably the job of the rest of the code. If you still have trouble, show the complete program, preferably by making a snapshot of your workspace and posting just the link to it here.