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 trialElizabeth Almejo
1,358 Pointsreturn
Have tried a lot of variations, now trying things I don't think are correct. Can't move on, need help!
function max (2, 4) {
if >2 return 4
else return 4
}
return max;
1 Answer
KRIS NIKOLAISEN
54,971 PointsIt appears you are trying to check a single set of values instead of creating a function that can handle multiple values. For that you will need to specify parameters that follow the naming conventions for variables:
From w3schools
The general rules for constructing names for variables (unique identifiers) are:
- Names can contain letters, digits, underscores, and dollar signs.
- Names must begin with a letter
- Names can also begin with $ and _ (but we will not use it in this tutorial)
- Names are case sensitive (y and Y are different variables)
- Reserved words (like JavaScript keywords) cannot be used as names
To keep it simple lets just call them num1 and num2
function max (num1, num2) {
}
Then you are kind of the right track in using an if statement but you will want to compare the two numbers
if (num1 > num2)
The instructions want you to return the larger of the two numbers so if the above is true return num1. Otherwise you can keep it simple and return num2.