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

Jason Styron
PLUS
Jason Styron
Courses Plus Student 955 Points

Function Challenge

I keep getting a bummer message on this challenge with the question Did you pass 2 numbers to the max() function? I guess I am challenged myself because I am totally not getting this section, I thought I was passing the information inside the parenthesis when I called the function.

script.js
function max(lowest, highest) {
  return highest
}
max('40,50');
alert('50 is higher than 40');

1 Answer

Sorry but you didn't compare the two parameters which one is higher ; try this :

function max(a, b) {

  if (a < b) { // if a is lower than b
    return b; // we return b 
 } else { // if a is the higher number
        return a; //we return a
    }
}

alert(max(40,50)); // using alert to make it show the higher number : 40 or 50
Jason Styron
Jason Styron
Courses Plus Student 955 Points

Thank you. Seeing the code displayed like this makes sense to me now.

you re welcome, keep up the great work buddy