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 Pointsplease help!!!!
just cant figure this one out without the answer
function max(one,two){
if (one > two) {
return one;
} else if (two > one){
return two;
}
}
1 Answer
Robert Stewart
11,921 PointsI 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 PointsTodd Harvey
3,178 Pointsthats the answer on 1/2 im on 2/2 where i need to do an alert statement i think.