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 trialTodd Harvey
3,178 Pointsjust need toe answer here please
Need answers why here
function max(one,two){
if (one > two) {
return one;
}else if (two > one){
return two;
}
}
2 Answers
Steven Parker
231,236 PointsYou're very close, but you should still cover the case where both values are the same. You could do this by adding another "return" at the very end.
But another way would be if your first test does not pass, you can just return the other value right away without another test.
Once you pass task 1, then just call your function with any 2 values from inside an "alert" function call.
Robert Stewart
11,921 PointsI just posted this answer in your other topic about the same issue:
I just tried your solution and it worked. Which browser are you using? It may be a stretch, but since ES6 is not supported on all browsers it may not be able to run your code to validate it since you're using ES6 syntax.
Try this and see if it works, this is in the old syntax:
var max = function(one, two) {
if (one > two) {
return one;
} else if (two > one) {
return two;
}
}
As a side note you could also do:
function max(one, two) {
if (one > two) {
return one;
}
return two;
}
Since the first return statement stops the function from going any further the second return statement will only execute if one is not greater than two. (Makes your code a lot easier to read in the long run)
Todd Harvey
3,178 Pointsi got it. I had to type alert(max(2,3));
Todd Harvey
3,178 PointsTodd Harvey
3,178 Pointsi had to type alert(max(2,3));