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 trialDerek Khanna
Courses Plus Student 819 PointsThis prompt isn't making sense, my code works and it won't pass?
function max (num1, num2) {
if (num1 > num2) {
larger === num1
} else (num2 > num1) {
larger === num2
}
return larger;
}
2 Answers
KRIS NIKOLAISEN
54,971 PointsYour second version is closer in that you now:
- declare variable
larger
. However many of the challenges don't recognizeconst
orlet
and I'm not sure you'd useconst
there anyway. Tryvar
or better yet eliminate the variable and just return the value. - use an assignment operator when assigning
num1
andnum2
But you have one additional thing to change
-
else
shouldn't be followed by a condition. It is what executes when all previous conditions are false.
Steven Parker
231,269 PointsWhen you say "it works", how did you test it? At first glance I see these issues:
- the variable "larger" is never declared or assigned any value
- the "===" operator makes a comparison, use a single "=" to perform an assignment
- an "else" statement does not take a conditional expression (nor would it need one)
Derek Khanna
Courses Plus Student 819 PointsDerek Khanna
Courses Plus Student 819 PointsI tried this version too:
function max(num1, num2) { if (num1 > num2) { const larger = num1; } else (num2 > num1) { const larger = num2; }; return larger; }