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 Functions Pass Information Into Functions Create a max() Function

Hi guys where is the problem

script.js
function max (num1 ,num2) {
      return num1 + num2;

  if (num1 > num2 );

}
max(10 , 5);

2 Answers

Hi Raed!

Your logic is a little out of order:

Try this:

function max (num1 ,num2) { // Task 1
  if (num1 > num2) { // Determine which number is larger
    return num1; // If this one is larger, return it
  } else { // Otherwise
    return num2; // Return this one (because it's larger than num1, evidently)
  }
}

console.log( max(7, 3) ); // Task 2

In this case, the console will log:

> 7

Make sure to go back to the challenge's instructions and see how the code matches what was asked for.

By the way, I often try to test the code outside of Treehouse, to make sure it behaves as expected.

I generally test JS code here:

https://www.w3schools.com/js/tryit.asp?filename=tryjs_array

I hope that helps.

Stay safe and happy coding!

thanks Peter Vann

Hi

I've written this code and the test said : Bummer: It doesn't look like you created a function named max().

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

Could anyone help?