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 trialMax Milner
4,098 PointsIt says it can't find "variable numberA" and I don't know what it means.
I don't even have a variable, let alone one called numberA, so I'm not sure what I'm doing wrong.
function max( numberA, numberB) {
if ( numberA >= numberB) {
return numberA;
} else if (numberA <= numberB)
return numberB;
}
max(numberA, numberB);
alert(Math.random(numberA, numberB));
2 Answers
Heidi Puk Hermann
33,366 PointsYou define two variables in your function that you choose to call numberA and numberB. When you call your function, you need to provide the actual values, not their names. An example could be:
max(1,2);
In this case numberA is set to 1 and numberB is set to 2. The max-function would return 2.
Adam N
70,280 Points- You're trying to pass the numberA variable to the function, but it does not exist in your program
- You're supposed to pass the function call to alert. They only used Math.random() in the instructions as a way to show you that a func call can be passed to alert
Heidi Puk Hermann
33,366 PointsHeidi Puk Hermann
33,366 Pointsohh... and you do not have to call the
Math.random()
inside thealert()
. It was just used as an example in the exercise. In stead your should call yourmax()
inside the alert.alert(max(num1,num2));
where num1 and num2 are two numbers that you choose.