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 trialDaniel Williams
Courses Plus Student 1,325 Pointschallenge guidance
I am not sure how to approach or complete this challenge. can someone please help me to complete this challenge?
2 Answers
Leslie Wolfe
8,700 PointsThe question asks you to compare two numbers using two arguments. When I hear "compare," I think conditional. So "if, else" statements. We are creating a function with two arguments and then we will pass in two numbers to compare:
function max (num1, num2) { //function name with two parameters, num1 and num2
if (num1 > num2) { //comparing if num1 is greater than num2
return num1; //if num1 is greater than num2, return that value
} else { //if num1 is less than num2, return that value
return num2;
}
}
alert(max (3, 4)); //passing in 3, and 4 as num1, num2 and alerting the answer.
Good luck! Let me know if you need more explanation.
Leslie Wolfe
8,700 PointsAwesome Rich, Thank you for the tip! I was wondering about that - about to look it up. So noted...Cheers to you!
Daniel Williams
Courses Plus Student 1,325 PointsThanks guys. I really do appreciate the support. Looking forward to mastering JavaScript. Again thanks a Mil
Rich Donnellan
Treehouse Moderator 27,696 PointsRich Donnellan
Treehouse Moderator 27,696 PointsHey, Leslie!
To get proper syntax highlighting, add the language you intend it to be after the three backticks (in this case ```
js
). Already edited for you here, but keep in mind for future use!Cheers!