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 Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Can'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.

script.js
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
Steven Parker
231,236 Points

Most 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.