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 trialNeale Potgieter
3,715 PointsNeed help with the syntax of this quiz
I keep receiving a syntax error on the following code: function max(n1,n2){ if (n1>n2){ return true}; else { return false}; }
max(1,2);
function max(n1,n2){
if (n1>n2){
return true};
else {
return false};
}
max(1,2);
3 Answers
Serge Kagiema - Fay
2,879 PointsWhat number should the max function should return?
A function can return a value by using the return keyword. So, you have one of those scenarios:
function max(n1,n2){ if (n1>n2){ return n1} else { return n2} }
OR
function max(n1,n2){ if (n1>n2){ return n2} else { return n1} }
Serge Kagiema - Fay
2,879 PointsHello there,
You need to remove the semicolons Your code must like this.
function max(n1,n2){ if (n1>n2){ return true } else { return false } }
And it will work
Neale Potgieter
3,715 PointsThanks - the semicolon clean-up resolved my syntax error but I can't get the max to return a value. This is my error now: "The max
function isn't returning a number."
I am not sure why it isn't fetching the number from calling my max function below the code.
Neale Potgieter
3,715 PointsNeale Potgieter
3,715 PointsThanks, that resolved it for me.