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
Willie Suggs
Courses Plus Student 5,879 Pointsneed help understanding how to use conditional statements in a javascript function
im pose to make a function named max and give it two number parameters then make the function return the highest value
function max(2, 5) {
if(2 < 5) {
return max(5);
}
}
function max(2, 5) {
if(max === 5) {
return 5;
}
}
1 Answer
Chyno Deluxe
16,936 PointsHey Kendra, you have the right idea however a couple changes need to be made.
/*
this function checks if number 1 is greater than number 2.
if it is then it returns number 1 else it returns number 2
*/
function max(num1, num2) {
if(num1 < num2) {
return num2;
} else {
return num1;
}
}
//you call a function like below
max(2,5);
I hope this helps.
Willie Suggs
Courses Plus Student 5,879 PointsWillie Suggs
Courses Plus Student 5,879 Pointsthanks