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 trialVytautas Dargis
5,715 PointsBelow is the case. I not sure how to pass.
Create a new function named max() which accepts two numbers as arguments. 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.
function max(2, 5) { if(2 > 5) { console.log(true); } else { console.log(false); } }
function max(2, 5) {
if(2 > 5) {
console.log(true);
} else {
console.log(false);
}
}
7 Answers
Dan Oswalt
23,438 PointsYou need to return the larger number, not a true/false. And these need to be named parameters, so:
function max(a, b) {
if(a > b) {
return a;
} else {
return b;
}
}
Vytautas Dargis
5,715 PointsThanks
Abe Layee
8,378 PointsFirst of all, you need to create the max() function and pass it two arguments. Then compare those arguments with if else . Lastly, alert the max() funtion.
function max(a,b){};
Compare a and b with if else statement
if(a>b) { // is a greater than b?
return a;
}
else {
return b;
}
max(10,1)// 10 represents a and 1 is b... now we pass the arguments to the function once we call it.
Lastly, we alert the max function using the alert method.
alert(max(10,1)); //you can delete the above the else statement max() function for the second part.
Vytautas Dargis
5,715 PointsMany thanks. I passed.
Vytautas Dargis
5,715 PointsMany thanks. I passed.
Abe Layee
8,378 Pointsglad I could help;D
Vytautas Dargis
5,715 Points(Y)