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

Abdullah Al Faruk
PLUS
Abdullah Al Faruk
Courses Plus Student 3,270 Points

How to solve it? Anyone there who can help me ?

Can any one help me to make it done ? I don't understand exactly, how to I solve this issue?

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

1 Answer

Thomas Nilsen
Thomas Nilsen
14,957 Points

The max-function is supposed to return the biggest number out of the two passed in.

Your function as is, returns the two arguments concatenated. If I pass in 2 and 3 to your function, i would get back the string "2 3".

Here is how it should be:

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

or you could also write the a bit shorter:

function max( one, two ) {
  return one > two ? one : two;
}