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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Christina Perez
Christina Perez
2,605 Points

Why 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.

script.js
function max (one, two) {
  return (one, two);
}
max 

1 Answer

You 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
Christina Perez
2,605 Points

Hey 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? :/

Sorry, Its been a long day. Do you mean that the code you posted above passed the challenge?

yeah 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.

this is what the challenge should look like:

function max(a,b) {
  if(a > b){
    return a;
  }else{
    return b; 
  }
}

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
Andrew Kiernan
26,892 Points

Hey 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:

function max(one, two) {
  return two;
}

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 parameter two, which happens to always be the larger number for this challenge.

Hope that clears some things up!