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

Ali Corlett
PLUS
Ali Corlett
Courses Plus Student 1,359 Points

beneath max function add a 'call' in alert format.

I run this and I get, now No1 isn't passing. I go back. I change nothing, No1 passes. I am calling the function called 'max' and it has the two "numbers a, b". I really don't understand why the alert isn't showing a result as 'a'.

It is outside code block. It doesn't need an end brace. I think it should call function max and display 'a' as being more than b.

I am totally dumbfounded. Can you help?

script.js
function max (a, b) {

   if (a > b)  {
   return a;
 } else  {  return b; }

}
alert( max (a,b) );

2 Answers

//Just pass numbers when you call the function and should be work fine. Something like this:

alert( max (3,5) );
Ali Corlett
PLUS
Ali Corlett
Courses Plus Student 1,359 Points

Thanks so much. I was confused by the video that said alphas could be used and sorted in order like a number. This worked. thanks.