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 trialCarlos Marin
2,675 Pointscreating a max function
"Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the result of the function to the alert method."
I am confused a bit here. I have been stuck at this problem for over a week now and I still can't seem to figure it out. What is the problem? it says "oops! It looks like task 1 is no longer passing." but I have not changed any of the code I typed in task one.
function max (one, six) {
if ( one > six ) {
return one;
} else {
return six;
}
}
alert( max(one, six) );
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! The second step asks you to pass in two numbers , but you are passing in two undefined variables. This is causing a syntax error which means that the code can no longer be interpreted.
The parameters in the function definition one
and six
will be assigned any values we send in when we call the function. So if I were to do this:
alert( max(20, 3) );
I would then pass in 20 which would be assigned to the variable one
and 3 which would be assigned to the value six
. I feel like you might have confused yourself here a bit by making parameter names the name of a number. I might have chosen the names num1
and num2
.
function max (num1, num2) {
if ( num1 > num2 ) {
return num1;
} else {
return num2;
}
}
It will take the first number we send in and assign the value to num1
and the second number to num2
.
Hope this helps!
Carlos Marin
2,675 Pointsoh okay I see, so when I call the function it ask me for the replacements/input/argument? when I make the function I make the parameters/question?
Thank you Jennifer, you were of great help!
ilya A
3,802 Pointsilya A
3,802 PointsWhy does this pass!?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse Teacherilya A because the first part of the code is absolutely correct. Although you have the
alert
in there, I believe Treehouse is ignoring that. It's Treehouse that's running that function... not you. When they run the function they will send in two numbers of their choosing and we have no idea what those are, so the code must work for any two numbers sent in.