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

Thaddeus Lorenz
Thaddeus Lorenz
3,434 Points

what am i doing wrong?

Im guessing from the problem that you need to have a random number selected then determine which number is bigger than the other. I tried the randomNumber variable to see if that would work but it's not working for some reason. Please help me.

script.js
function max ( one , two ) {
  var randomNumber= Math.floor(Math.random() > two) +1;
  if (randomNumber); {
   alert("Congrats");
  } else {
    alert("Nope");
   }
   return max;

2 Answers

Steven Parker
Steven Parker
231,269 Points

There's nothing random about this challenge.

The function you create for task 1 should only compare the two argument values with each other, and return one of them based on that comparison. It also won't need to do any alerts.

In task 2, you'll write some code after the function that will use it in an alert. The instructions show an example of how to use alert to return the value of a function, and it uses Math.random() in the example, but that won't be what you use.. You'll call your own max function instead.

Thaddeus Lorenz
Thaddeus Lorenz
3,434 Points

I understand what you are saying for the alert message, but I am stuck on the part where I have to compare the two argument values and creating the conditional statement to compare them.

Steven Parker
Steven Parker
231,269 Points

A simple inequality comparison between items named a and b might look like this:

if (a > b)  {
  // do what you need to do if a is larger
} else {
  // do what you need to do if b is larger (or equal)
}
Jonathan Hellstrand
Jonathan Hellstrand
4,216 Points

Along with what Steven said about task one, I noticed you have a semi-colon after your if statement:

 if (randomNumber);<-- {

If you remove this, you would at least get your alerts.