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

Robert Rydlewski
Robert Rydlewski
3,828 Points

What'sc wrong with this code ??? I created the function, I made the argument of (4,9) inside the function and made ..

and made the conditional statement. What I missing ??? Please help

script.js
function max(x,y) {
 return max(4,9)
  if (x < y ) {
    document.write("x is bigger then y");
  }
  else {
    document.write("x is smaller then y");
}

Hi Robert there a couple of issues with the code that has been written. Where you have called the function, this will not work, the function needs to be called outside of the function. Also try calling it without the return as well.

function max(x,y) {
  if (x < y ) {
    document.write("x is bigger then y");
  } else {
    document.write("x is smaller then y");
  }
}

max(4,9)

Hope this helped.

2 Answers

Robert Rydlewski
Robert Rydlewski
3,828 Points

Thanks, guys :) I appreciate your help