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 trialNick Stumpf
9,602 Pointsnot sure what I need to change...
I'm not sure if my alert is in the right spot, it keeps saying "doesnt look like you used the alert method". What do I need to fix?
function max(number1, number2) {
if (number1 > number2)
return number1;
else return number2;
alert( max(number1, number2) );
}
3 Answers
Steven Parker
231,236 PointsThe function shouldn't be modified. The alert call needs to be done outside (after) the function.
Adam Beer
11,314 PointsAnd please fixed the curly brackets inside the max function.
Adam Beer
11,314 PointsWhen you simply use if statement without else if/else you don't need curly brackets..
Steven Parker
231,236 PointsIt doesn't matter if you have "else if" or "else", the braces ("curly brackets") are optional as long as the conditional body contains only one statement. So that part of this code is fine as-is.
Adam Beer
11,314 PointsThank you!
Matthew Lestina
Courses Plus Student 122 PointsMy 2 cents as an intermediate, I would do this:
function max(number1, number2) {
if (number1 > number2) {
return number1;
}
else {
return number2;
}
}
In other words, you failed to use curly brackets {} twice within the if statement
Steven Parker
231,236 PointsAs I mentioned above, the braces are optional when the conditional code is one single statement. So your example is fine, but so it the original code (in that regard).
Nick Stumpf
9,602 PointsNick Stumpf
9,602 PointsThanks Steven, I went back and reviewed more videos and have tried it a bunch of different ways but now when I place the alert call outside the the function it says "task 1 is no longer passing" ...?
Adam Beer
11,314 PointsAdam Beer
11,314 PointsWhen you finished the first task don't change the code in the second task. Use alert dialog and add inside to max(number1, number2) function. Change write number1,number2 to two numbers inside the max function.