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 trialJosephine Tendai Machakaire
1,865 PointsCan you please assist with the question below: Create a new function named max which accepts two numbers as arguments (y
Create a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would l
var
function max(arg1, arg2) {
return large;
}
if
4 Answers
Brandon VanCamp
Front End Web Development Techdegree Graduate 30,954 PointsHey Josephine,
function max(num1, num2) { // num1 && num2 are our arguments
// Next we need to figure out what number is greater, num1 or num2. In this case we are passing 12 = num1 and 3 = num2..
if(num1 > num2) { // So if num1 is greater, which it is in this case.
return num1; // We then return num1
} else {
return num2;
}
}
console.log(max(12, 3));
Another case if num2 happened to be our greater number.
function max(num1, num2) { // num1 && num2 are our arguments
// Next we need to figure out what number is greater, num1 or num2. In this case we are passing 1 = num1 and 31 = num2..
if(num1 > num2) { // So if num1 is greater, which now it's NOT && ='s( equals ) false.
return num1;
} else {
return num2; // We then return num2
}
}
console.log(max(1, 31));
Hopefully this helps you out. Let me know if you need further help, thanks.
Roberts Peirāgs
Front End Web Development Techdegree Student 3,297 Pointsfunction max(a, b) { if (a > b) { return a; } else { return b; } }
Omar Ocampo
3,166 Pointsfunction max(10, 50) {
if (10 > 50) {
return 10;
} else {
return 50;
}
}
/* function max(a, b) { if (a > b) { return a; } else { return b; } } */
I'm sorry, I'm doing accordin this example; but it does not work for me, Could assist me you this please
Omar Ocampo
3,166 PointsDays ago posting request to my problem and no answers, please, anyone can help?
Roberts Peirāgs
Front End Web Development Techdegree Student 3,297 Pointsfunction max(a,b) { if (a > b) { return("first is greater"); } else { return("second is greater"); }
max(4,5);
Josephine Tendai Machakaire
1,865 Pointsits saying the 'max' function isn't returning a number. How do i correct that error?
Josephine Tendai Machakaire
1,865 PointsJosephine Tendai Machakaire
1,865 PointsThank you soo much.. It has really helped
Omar Ocampo
3,166 PointsOmar Ocampo
3,166 PointsI'm sorry, it didn't work for me