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

I know I'm messing up on the variable portion, can someone help me?

script.js
function max(velocity, speed) {
  var randomNumber = Math.floor( Math.random() + speed + velcity); 
  if(velocity > speed) {
     return velocity;
} 
   else {
     return speed; 
}

max(1,2);

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

You are creating unnecessary code for outside of the scope of the challenge. You have the code right in the function, now you just need to rectify it:

function max(velocity, speed) {
  if (velocity > speed) {
    return velocity;
  } else {
    return speed;
  }
}

The second task requires you to use the alert command and pass in max function with two arguments (numbers), for example:

alert(max(5, 3));

Thank you !