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

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
229,732 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.