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 trialChristina Perez
2,605 PointsWhy does part one pass without the conditional statements?
The right answer needs to have conditional statements but it doesn't pick up on the missing information.
function max (one, two) {
return (one, two);
}
max
1 Answer
Jacob Mishkin
23,118 PointsYou did not write a conditional statement inside the function max. you returned two parameters.
remember a conditional statement looks like this:
if('condition'){
//run code here
}else {
//run code here
}
Christina Perez
2,605 PointsChristina Perez
2,605 PointsHey Jacob. Yes I totally know that. I guess I was just wondering if this was an error on the part of Treehouse? It should have told me I didn't do it right. Does that make sense? :/
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 PointsSorry, Its been a long day. Do you mean that the code you posted above passed the challenge?
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsyeah so, I ran your code and yes it did pass. Let's find out why, I will say that I highly doubt this is a bug on Treehouse, but maybe.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsthis is what the challenge should look like:
but to be honest with you, I think it's a bug. I ran the prior code in codepen and as I thought it only returns the two parameter. So I guess this is an issue.
Andrew Kiernan
26,892 PointsAndrew Kiernan
26,892 PointsHey Christina,
So it looks like the challenge is testing with the assumption that
two
is always the larger number. You can get the challenge to pass by simply writing:In JavaScript, tuples (pairs of values) are not an acceptable data type, and JavaScript simply drops the first and returns the second, so your
max
function is doing the same as the function above, and returning the parametertwo
, which happens to always be the larger number for this challenge.Hope that clears some things up!