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 how to write a code that compares two values and returns the highest value to the function

I can't figure out how to pass this test. Having a hard time understanding the question and determining the proper code

script.js
function max(low, high) {
  var largest = largest()
      if (low < high){
  max = high;
  } else (low > high) {
   max = low;
  }
}  
return max;

2 Answers

Abe Layee
Abe Layee
8,378 Points

You're so close , but you want to pass a number when you call the function. Also use the return method

function max(low, high) {
  var largest = largest()
      if (low < high){
  max = high;
  } else (low > high) {
   max = low;
  }
}  
return max;

You want something like this

function max(low, high) {
      if (low < high){
      return low
  }  
   else {
     return high;
     }

}  

max(10,20)// 10 is for low and 20 for high

Thank you for the help and explanation

Abe Layee
Abe Layee
8,378 Points

You're welcome bro:D