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 Pointscreating a function with two arguments
i don't understand what am doing wrong here but it is not calling the function max back and i tried calling it...
function max(firstNumber, secondNumber){
firstNumber = 12;
secondNumber = 5;
if (firstNumber > secondNumber){
return firstNumber;
}else if{
firstNumber === secondNumber;
} else{
return secondNumber;
}
}
2 Answers
Adam Beer
11,314 PointsI think you delete the second third line. Don't use else if() statement. The first if() good, think about it, if the first statement is not true then a solution remains.
if (firstNumber > secondNumber){
return firstNumber;
} else{
return secondNumber;
}
or use shorthand
if (firstNumber > secondNumber){
return firstNumber;
}
return secondNumber;
Call the max() function outside of the max() function. Enter two parameters (two numbers), like this,
max(firstNumber, secondNumber);
Hope this help!
kingdavid igbayilola
8,678 PointsThanks a lot it worked
kingdavid igbayilola
8,678 Pointskingdavid igbayilola
8,678 PointsThanks but my code can't find the variable
Adam Beer
11,314 PointsAdam Beer
11,314 PointsWhat kind of variable? No need to variable. Just call the max() function and give it two parameters, (two numbers), like this,
What happened now?