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

I can't figure out the answer.

function max(number1,number2){

if(parseInt(number1)>>ParseInt(number2)){ return number1; } if else(parseInt(number1)<<parseInt(number2)){ return number2; } }

max(1,2);

script.js
function max(number1,number2){

if(parseInt(number1)>>ParseInt(number2)){
   return number1;
}
if else(parseInt(number1)<<parseInt(number2)){
   return number2;
}
}

max(1,2);
Sandro Das Neves
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sandro Das Neves
Front End Web Development Techdegree Graduate 23,426 Points

a parse error don't need to use parseInt. you can delete them. I give you the solution try.

function max(number1,number2){

if(number1 > number2){
   return number1;
}
  else {
   return number2;
  }
}

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Gaku

if(parseInt(number1)>>ParseInt(number2)){

Since JavaScript is case-sensitive ParseInt must begin with a lowercase P, but this was probably just a typo. Comparisons for greater than and less than are done with either > or <. What you are using, << and >> are actually bitwise operators (which I don't think are covered here).

if(condition){
   // code
}
if else(condition){
   // code
}

The proper way to structure an if else statement is:

if(condition){
   // code
} else {
   // code
}

Since the question never actually asks you to convert any inputs to integers, you can simply leave it off.

function max(number1, number2){
  if(number1 > number1){
     return number1;
  } else {
     return number2;
  }
}

thank you very much,I finally got it!!