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

Code Challenge: Create a max() function

function max ( 10 , 20 ) { if (10>20) { return false; } else { return true; } }; where am i wrong? How can i code this?

script.js
function max ( 10 , 20 ) {
  if (10>20) {
    return false;
  } else {
    return true;
  }
};

2 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Sarfaraj

Your logic is correct only you are not using variables you have instead simply typed in 2 numbers. The function below which passes the test uses the same layout as your but instead accepts the 2 variables i and x.

The challenge asks you to return the higher of the 2 values so instead of returning true or false simply return the variable i or x whichever is the biggest.

function max(i,x){

  if(x > i){

    return x;

  }else{

    return i;

  }


}

Hope this helps

Daniel

Carlos Esteves
Carlos Esteves
8,563 Points

Hi Martin,

Thanks for your help. I was with the same problem, and now I understand the mistake.