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 trialKshitij Sinha
3,186 PointsDon't know why this code quiz wont work
I have to make a fucntion called max and take 2 numbers as arguments and then return the greater. i tried doing it with variables but still wont work
function max(10,9) {
if(10>9)
{
return 10;
}
}
function max(10,9)
{
if(10 > 9) {
return 10;
}
}
2 Answers
Grace Kelly
33,990 PointsHi Kshitij, I would not put numbers into the function parameters, instead use variables e.g x and y, also you need to add an else if statement to check if the second parameter is greater than the first, like so:
function max(x,y) // use variables for parameters
{
if(x > y) {
return x;
} else if (y > x) { //add else if statement to check if y is greater than x
return y;
}
}
Hope that helps!!
Kshitij Sinha
3,186 PointsThank you. Works well now
Eric Ferrer
9,378 PointsEric Ferrer
9,378 PointsDon't hardcode in the numbers but instead put in some variable names and compares those.