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 trialjeffreylin2
1,902 Pointsthis doesn't work? function max( num1, num2 ){ } if ( num1 > num2 ){ return num1; } else { return num2; }
i'm stuck on the challenge task 1 of 2 asking to create a new function and returning the larger number using conditional statements. thanks!
function max( num1, num2 ){
}
if ( num1 > num2 ){
return num1;
} else {
return num2;
}
2 Answers
Samuel Webb
25,370 PointsJeffrey,
The problem is that you're ending the function before the conditional statement. The if statement should be inside of the max function, not after it. Your code should look like this:
function max(num1, num2){
if (num1 > num2){
return num1;
} else {
return num2
}
}
Hope this helps.
Cheers, Sam
jeffreylin2
1,902 PointsThanks Samuel!
Samuel Webb
25,370 PointsNo problem. Glad I could help.