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

Cristina Kouri
Cristina Kouri
3,652 Points

Can someone please explain this challenge to me?

I just don't seem to be getting it. Any help would be appreciated, thanks!

script.js
function max(x, y) {
  if(x > y) {
    return x;
} else (y > x) {
    return y;
}

max(10, 12);  

2 Answers

Collin Halliday
seal-mask
.a{fill-rule:evenodd;}techdegree
Collin Halliday
Full Stack JavaScript Techdegree Student 17,491 Points

Hey Cristina.

It looks like you are missing a closing bracket for your max function. You also need to make your else statement an "else if" statement if you are going to include a condition to test after it. Something like, "else if(y > x)". I believe that with those changes, your code should pass the first part of the challenge.

As an aside, it's a good idea to include an else statement at the end to handle the situation in which the numbers passed to the function are of equal value. However, that appears to be beyond the scope of this lesson.

I hope that helps. Let me know if you have further questions or if you run into any problems on the second part of the challenge. Best of luck!

Cristina Kouri
Cristina Kouri
3,652 Points

Hey Collin,

Thanks so much, it worked! I appreciate the advice - I just gotta keep practicing these functions and if statements!

Cristina