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 trialPayal Sen
1,286 PointsWhat is wrong with this code?
I can't figure out where is the mistake it keeps on asking if I have passed 2 number to my function but which is already there. Any help would be appreciated, is it a syntax error?
function max(a, b){
if (a>b){
alert(a + "is bigger than" + b);
return a;
}
else
{
alert (b + "is bigger than" + a);
return b;
}
};
alert (max (12, 56));
1 Answer
Alexander Davison
65,469 PointsFirst, you don't need to call the function, and second, you should have spaces at the beginning and end of the strings so that it wouldn't print something like "3is bigger than2" and instead "3 is bigger than 2".
Try this:
function max(a, b){
if (a > b) {
alert(a + " is bigger than " + b);
return a;
} else {
alert(b + " is bigger than " + a);
return b;
}
}
Good luck! ~Alex