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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 PointsPredefined 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
Full Stack JavaScript Techdegree Student 17,509 PointsHey there, several problems exist that I can see.
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().
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!
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHey Trent, thankyou so much for the assistance. It helps thanks again