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

peterson st gourdain
peterson st gourdain
931 Points

LOST

I NEED A LITTLE CLARITY

script.js
function max (A17, P19) {
  if (A17 >= P19) {
      return A17; 
  } else {
    return P19;
  }
}
max(A17, P19)
alert( Math.random() );

1 Answer

Ian Billings
PLUS
Ian Billings
Courses Plus Student 7,494 Points

Hi,

Your function looks good. For the second part of the challenge you need to call the function max with 2 numbers, and in your code you have used the variables names again which don't mean anything to the computer. E.g. max(4, 9) (Which should return 9). You then need to store that result into a variable, so I would do something like

var result = max(4, 9);

Then finally you need to alert the result, so I would do:

alert(result);

Hope that helps.