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

Brok Sorensen
Brok Sorensen
1,578 Points

How are you supposed to write the conditional statement for this one? Am i even close?

I am supposed to use a conditional statement to determine which number is larger and return that number. Please Help.

script.js
function max (number1, number2){
  return if(parseInt(number1) > parseInt(number2)){parseInt(number1)}
  else {parseInt(number2)}
}

2 Answers

Tiffany White
Tiffany White
5,373 Points

You are putting your return statements in the wrong place.

Ideally, you'd want the return statement after each conditional. I'll give you a head start.

function max (num1, num2) {
  if (...code...) {
   return // what will this return? Needs to return a number
  } else {
   return //if whatever number you have come up with isn't greater than the other, what should it return?
  }
}

You don't need the parseInt in this instance.

Brok Sorensen
Brok Sorensen
1,578 Points

Thanks Tiffany. That makes more sense.

Tiffany White
Tiffany White
5,373 Points

Brok Sorensen If my answer is good, could you accept it? I hope I've helped. Let me know if you have anything else.