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

Carl Sergile
Carl Sergile
16,570 Points

What am I doing wrong?

Hey need some help>>

script.js
function max(two, four) {
  if (two < four ) {
    return true
  }
  else {
    return false
};

2 Answers

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Carl,

there are a few problems in your code. Firstly you forgot to close your else clause, secondly you're returning boolean values instead of the numbers. The goal of the challenge is to return the bigger number. I kept your variable names and changed your code so it's working:

function max(two, four) {
  if (two < four ) {
    return four;
  } else if(two > four) {
    return two;
  }
}

Also note that it would be better to use an else if instead of an else because if the two values would be equal, the else would be executed and a number would be returned even if it's not bigger. I hope that helps, if you have further questions feel free to ask them, good luck! :)

Hi Carl,

So your structure is okay, but your missing the closing bracket.

function max(two, four) {
  if (two > four) {
    return true
  } else {
    return false
  };
}

Hope this helps. Keep Coding! :)