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 trialFRANKIE Ochoa
2,759 Pointscan someone please help I don't understand
function max (3, 6) {
if (6 > 3) {
return 6;
} else {
return 3;
}
console.log( addNumbers(3,6) );
2 Answers
Peter Vann
36,427 PointsBonus:
I prefer declaring functions like this, however:
const max = function (a, b) {
if (b > a) {
return b;
} else {
return a;
}
}
which can also be shortened to this using ES6 arrow function syntax:
const max = (a, b) => {
if (b > a) {
return b;
} else {
return a;
}
}
More info on ES6: https://codeutopia.net/blog/2015/01/06/es6-what-are-the-benefits-of-the-new-features-in-practice/
Peter Vann
36,427 PointsThe objective is: Create a function named max that accepts two numbers as arguments (name the parameters whatever you would like). The function should return the larger of the two numbers.
(Hint: pass the parameters in the function as variables, as in 'a' & 'b' or 'x' & 'y' or 'param1' & 'param2')
So my solution would be
function max (a, b) {
if (b > a) {
return b;
} else {
return a;
}
}
console.log( max(4, 7) );
Will log 7 to the console.
FRANKIE Ochoa
2,759 Pointsthank you so much
FRANKIE Ochoa
2,759 PointsFRANKIE Ochoa
2,759 Pointsthank you that helps alot