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 trialAndrew Boschee
8,824 Pointsnot sure if I am incorporating the if and else if statement properly to return the high number
following off of the video, aside from the if and else if loops, but I'm not sure if I am properly declaring the highNumber variable or if properly trying to return the highNumber .
function maxNum (firstNumber, secondNumber){
var highNumber;
if {
(firstNumber>secondNumber)
return highNumber;
}
else if{
(firstNumber<secondNumber)
return highNumber;
}
}
console.log(maxNum(10,20));
1 Answer
Steven Parker
231,269 PointsHere's a few hints:
- you don't need to create any new variables
- you will return either firstNumber or secondNumber
- you will compare them against each other to determine which one is larger
- the conditional expression (in parentheses) of a "if" statement comes before the open brace of the code block
- you can use a plain "else" (instead of "else if") to respond to all other conditions
- a plain else does not have a conditional expression
benjaminnaesen
2,349 Pointsbenjaminnaesen
2,349 PointsI think you're making it slightly too difficult on yourself. You don't actually need the var highNumber for this.
Second of all, an if conditional statement is made like this: if the firstNumber is bigger than the secondNumber, return the number that is bigger (firstNumber).
Now try and do the else if in the same way but with secondNumber being bigger than firstNumber. :) If you still can't find it, just tell me and I'll try to explain it more.