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 trialAdam Gheli
3,714 PointsJS Challenge max function
Code I'm using is:
function max(one, two){ if (one >= two) { alert (one); } else { alert (two); } } max(1,2);
function max(one, two){
if (one >= two) {
alert (one);
}
else {
alert (two);
}
}
1 Answer
Chris Bennett
7,499 PointsI think you need to add a return statement in the if/else block.
Heres my code I tested it and it works on the test:
function max(one,two){
if(one > two){
return one;
} else if(two>one){
return two;
}
}
Chris Bennett
7,499 PointsChris Bennett
7,499 PointsThe if else statements ask if the first number is greater return that number, else if the second number is greater return the second number.
It doesn't do anything if they are equal since that isn't a requirement of the problem on the challenge.
Hope this helps Ali.