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

create max() function method

I tried multiple ways to beat the second step of the challenge.. can someone show me what I'm doing wrong? They want me to store the max() in the alert() dialog box, but it isn't working. Thanks!

script.js
function max(numA, numB) {
  if (numA > numB) {
   return numA; 
  } else {
   return numB; 
  }
}
alert( max(numA,numB) );

5 Answers

Abe Layee
Abe Layee
8,378 Points

You're almost correct. You just have to pass a number when you call the max() function. Like this

 alert(max(10,3)) // 10 for numA and 3 for numB
Nicolas Sandller
Nicolas Sandller
5,643 Points

give us some context, what is the error that pops up?

It ask me if I put the two number parameters inside the max() function.

Wow thanks Abraham! It worked and now I understand it better :D

Abe Layee
Abe Layee
8,378 Points

You're welcome:D

Wow thanks Abraham! It worked and now I understand it better :D