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 trialNassor Khalfani
5,058 Pointsreturn max
whats the syntax to return a the max number again
function max (411, 818)
{
return 411;
}
3 Answers
Amber Cyr
19,699 PointsThe syntax for your particular data set would be as follows
function max(num1, num2){
if(num1 > num2){
return num1;
}else{
return num2;
}
}
max(411, 818);
If you would like the largest number in an array of numbers, the syntax would be
let numbers = [1, 6, 3, 45, 9, 11, 345, 78, 19];
function max(){
let maxNum = numbers[0];
for(num in numbers){
if(numbers[num] > maxNum){
maxNum = numbers[num];
}
} return maxNum;
}
max();
hamdi ismail
Courses Plus Student 8,927 Pointswell first of all you should not put a numbers as arguments you should put a refrence like a and b then if the function u will need to use if statement
function max(a, b) {
if (a>b) {
return a;
}
return b;
}
Larry Coonrod
5,041 PointsYou need to set up a conditional statement to return the larger number. Hint: use a comparison operator in the if condition.
function max ( first number, second number) {
if (condition) {
return
} else {
return
}
}
max()