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 trialTom Daugherty
4,821 Pointsfunctions
It says that I have not created a function named max and I believe I have.
function max(a, b) {
max = (5, 9)
if (5 > 9) {
return( max )
} else {
return( max )
}
}
max()
3 Answers
Colin Bell
29,679 PointsYou've created a function that takes two parameters - a
& b
. But you're trying to pass arguments inside the function. You just want to check generally which of the two parameters is the larger number. So if a > b
you want to return a
, otherwise return b
(Keep in mind that this would also return b
if they were equal).
function max (a, b) {
if (a > b) {
return a;
} else {
return b;
}
}
Then you'd pass the arguments when you call it:
max(5, 9);
Michael Hall
Courses Plus Student 30,909 PointsYou have created a function called max. The problem is in the call. You just need to add an ' ; ' at the end. Like this:
max();
Tom Daugherty
4,821 PointsThank you.
Zoltán Holik
3,401 Pointsfunction max(a, b) {
if (a > b) {
return a + " greater than " + b;
} else {
return a + " not greater than " + b;
}
}
var result = max(5, 9);
alert(result);
Tom Daugherty
4,821 PointsTom Daugherty
4,821 PointsThank you so much I knew I was close but I just couldn't get over that hump?