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 trialAustin Jimison
3,849 Pointsnumbers not passing through my call function
I'm uncertain why the error of me not passing numbers through my call function is appearing.
function max (first, second) {
var biggerNumber = "";
if (first > second) {
var biggerNumber = first;
alert(first + ' is the larger number.');
} else {
var biggerNumber = second;
alert(second + ' is the larger number.');
}
return biggerNumber;
}
alert( max(20, 45) );
2 Answers
Andrew Kiernan
26,892 PointsHey Austin!
You don't need to call alerts within your max()
function, just return the larger of the 2 numbers. You also don't need to create an extra variable (biggerNumber
), as the parameters are already defined variables.
function max(x, y) {
if (x > y) {
return x;
}
if (x < y) {
return y;
}
}
That should do it!
Austin Jimison
3,849 PointsMuch obliged, Andrew! It worked!