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 trialkingdavid igbayilola
8,678 Pointsfunction can't find the variable
I don't understand why my code can't find the variable but looking at it , i can't find anything wrong
function max(firstNumber, secondNumber) {
var firstNumber =12;
var secondNumber = 5;
if (firstNumber > secondNumber){
return firstNumber;
} else{
return secondNumber;
}
}
max(firstNumber, secondNumber);
1 Answer
Niclas Hilmersson
8,296 PointsOk what you need to do is remove those variables. the function uses the two parameters inside of the first function call to get the numbers.
When you call the function like this max(12, 5);
that's gonna set the numbers for the parameters that you have set as variables. Therefore you don't want to create any variables inside the function. imagine that the numbers written inside of the function call at the end. Replaces the parameter of firstNumber and secondNumber
function max(firstNumber, secondNumber) {
if (firstNumber > secondNumber){
return firstNumber;
} else{
return secondNumber;
}
}
max(12, 5);