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 trialZachary Pratt
2,395 PointsHow to Creat the Max Function with a Conditional Statement
I am not sure what I'm missing here.
function max(1, 2) {
if (1 > 2)
Return 1;
}
if (2 > 1)
Return 2;
}
}
2 Answers
Craig Watson
27,930 PointsHi Zachary,
It seems there was a couple of things going a miss but nothing major; firstly you were passing the number in the original functions declaration and the question wanted you to make a function that "accepted" two numbers. So for this you just need two place holders.
Secondly you had wrote out two "if's" and you needed and "if else" :)
The coded below will get you through the challenge and this is a good quick overview of javascript functions. (I had to look here to jog my memory)
function max($i, $e) {
if ( $i > $e ) {
return $i;
} else {
return $e;
}
}
alert ( max( 1, 2 ) );
Hope this helps Craig
akak
29,445 PointsYou are missing opening curly brackets after each if statement :)
Zachary Pratt
2,395 PointsZachary Pratt
2,395 PointsThis did not work either
Zachary Pratt
2,395 PointsZachary Pratt
2,395 PointsThanks Craig. My error. It did work! This is the Best Answer!