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 trialJorge Vazquez
2,890 PointsSyntax error
How do solve this one!
function max (3, 6) {
if (3>6) {
return 3;
} else {
return 6;
}
}
max(3,6);
1 Answer
Steven Parker
231,236 PointsWhen you create a function, you don't use actual values as the parameters. Instead you use names which act as "placeholders" and represent the values that will be passed to the function when it is called in the program.
Just replace your numbers with names and you should pass task 1.
Then for task 2, when you call the function (and here the numbers are OK), just make your call be the argument to "alert()".
Adam McGrade
26,333 PointsAdam McGrade
26,333 PointsThe main purpose of creating a function is so that you can reuse the same code to perform a task many times. Your code is functionally correct, however it will not allow you to reuse the code, as your are providing values (3,6) in the declaration of the function as arguments. When declaring a function you want to use placeholder values so that the function can be reused with many numbers. When calling the function, you pass the values you wish to test into the method as arguments.
Now you are able to pass any two numbers, rather than 3,6 and it will perform the comparison for you.