
FRANKIE Ochoa
1,944 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
26,472 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.

Peter Vann
26,472 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/

FRANKIE Ochoa
1,944 Pointsthank you that helps alot
FRANKIE Ochoa
1,944 PointsFRANKIE Ochoa
1,944 Pointsthank you so much