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 trialShreemangal Sethi
Full Stack JavaScript Techdegree Student 15,552 PointsCan't get function to return.
function max(length, width){ var getLargerNum; return getLargerNum; } if(length > width){ document.write(length); }else{document.write(width); } max(100, 140);
This is my code for the challenge. I am not getting where am i going wrong. Every time i run the code an error message appears saying "Variable width not found". Is there a syntax error in my code.
function max(length, width){
var getLargerNum;
return getLargerNum;
}
var largerNum;
if(length > width){
document.write(length);
}else{document.write(width);
}
max(100, 140);
1 Answer
Steven Parker
231,271 PointsMost of the code here is not part of the function. The function ends when the code block is closed with an ending brace on the 4th line. You'll probably want to restructure things to make the function complete.
Also note that the function needs to return either one argument or the other. It won't need to write anything to the document.