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 trialMicah Dunson
34,368 PointsHow to use a conditional statement to test 2 numbers to see which is the larger inside an argument of a function?
I'm not sure how to use a conditional statement to test the 2 numbers to see which is the larger of the two.
The problem states: create a new function named max() which accepts two numbers as argument. the function should return the larger of the two numbers. you'll need to use a conditional statement to test the 2 numbers to see which is the larger of the two.
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHi micah,
With this challenge, first you need to create the function that takes in two arguments. So the challenge wants it named 'max,' so you would declare 'max' as a function. var max = function(one, two) {}
After that, you'll need to use an if statement to see which number passed in is greater. Basically you are telling the program that if one is greater than two, return one. And if two is greater than one, return two.
Overall, your code should look like this:
var max = function(one, two) {
if (one > two) {
return one;
} else {
return two; //you only have two variable to compare, so an if/else is all you need
}
}
Hope that helps clear things up. Keep Coding! :)
Micah Dunson
34,368 PointsMicah Dunson
34,368 PointsThanks for the help, much appreciated!!