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 trialTural Rzazade
3,750 PointsSolved the task in the last part
const regionDown = prompt("Where are you from, Europe or America?");
const region = regionDown.toUpperCase();
if (region === "AMERICA") {
function getArea(width, length, unit = "sq ft") {
const area = width * length;
return `${area} ${unit}`;
}
} else {
function getArea(width, length, unit = "sq ft") {
const area = width * length;
return `${area} ${unit}`;
}
}
I struggled first to figure out the way for getting unit based on the region that user is from, but then I used a conditional statement. I knew that I had to use conditional smth to get that but I guess "little things" (indentation/ quotes/ misspelled words) were making me think that it doesn't work.
1 Answer
Steven Parker
231,275 PointsIt's not clear why you would use a conditional here, since both branches contain exactly the same code. Did you perhaps intend for the 2nd definition to set the default unit to "sq meters" instead?
Also, instead of having two completely different definitions of the function, you could have just one and make use of the region setting inside the function code, or in the way the function is called.