Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Dwayne Munro
seal-mask
.a{fill-rule:evenodd;}techdegree
Dwayne Munro
Front End Web Development Techdegree Student 13,108 Points

how to solve the Create max() Function?

what is wrong with my code?

script.js
function max(40, 60) {
  prompt("The larger number is ");
}
max(60);
if (40 > 60) {
  document.write("try again");
} else {
  document.write("great job!"); 
} 

1 Answer

Steven Parker
Steven Parker
221,293 Points

:point_right: You have a few issues here:

  • Function arguments are never declared as literal values, they are variable names which will represent the values.
  • You have code that prompts for input, but that's not part of the challenge
  • You have code that writes to the console, but the challenge wants the results in a return statement.
  • You placed a closing brace after the first line of the function (ending the function)
  • You have a test that checks if 40 is larger than 60. That will never be true.
  • You should only define the function, not call it.

I strongly suggest you review at least some of the course videos, with a focus on function structure.