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

Creating Max

What's wrong with my code?

script.js
function max (12 , 8) {
 if (12>8) {
  return 12;
 }
 else {
 return 8;
 }
}

You need to supply the fucntion 2 arguments such as num and num2. then u check if num is greater than num 2, if it doesn't u return num2.

Thanks alot!

2 Answers

Steven Parker
Steven Parker
231,271 Points

Function parameters may not be numbers. They are effectively variables, and follow the same variable naming rules. So replace the numbers with names and you should pass the challenge.

Numbers can be passed as arguments later when you call the function.

I changed them to variables and gave those variables values, but it's still not working.

Steven Parker
Steven Parker
231,271 Points

The variables should only get values when the function is called. They should not get values in the function definition.

If that hint doesn't clear it up, show what the code looks like now.

function max (num , num2) {
 if (num>num2) {
  return num;
 }
 else {
 return num2;
 }
}

this code should work.