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

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Predefined Parameter

function getArea(width, length, unit){ unit = "sq. ft." const area = width * length; return ${area} ${unit}; }

If I try to enter a new value for unit it won't, is that because of the fact that argument is receiving a value in the beginning and then the value is getting assigned ?

1 Answer

Trent Nelson
seal-mask
.a{fill-rule:evenodd;}techdegree
Trent Nelson
Full Stack JavaScript Techdegree Student 17,509 Points

Hey there, several problems exist that I can see.

  1. You're immediately assigning a value of "sq. ft." to the unit variable. If you try to provide your own value like "meters", it's immediately overwritten. To correctly assign a default value to "unit" you need to declare it in the parameter field of getArea().

  2. Your return statement will also error due to the unexpected "}" from your handlebar variables. To resolve this wrap your statement in the proper template literal syntax using the ` character.

function getArea( width, length, unit = "sq. ft." ){ 
    const area = width * length; 
    return `${area} ${unit}`; 
}

getArea(10,20,"Meters");
//Should properly return "200 Meters".

Hope this helps!