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 trialseamoreatchu
Front End Web Development Techdegree Student 4,403 PointsHelp i think its broken
having troubles with this code... any suggestions?
function max(5 , 9){
if (5 + 9 = 14) {
return (14 - 5);
}
1 Answer
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi there,
let me see if I can help you out.
You've correctly defined your function and passed it parameters. But the parameters shouldn't be values. Parameters are basically another place to put variables. When you return the values later on they will look for the parameters to put the values in. And it's in returns that you can store the result of an expression.
So in the following example I've passed 2 parameters to the max function, num1
and num2
.
function max( num1, num2) {
//code
}
You would then test it by passing in those variables to an if condition like you tried.
function max(num1, num2){
if (num1 > num2 ) {
return ;
}
return ;
}
This checks that one number is bigger than the other. You can then return the appropriate variable and return the remaining one outside of the condition block. In programming, if the code inside of the condition cannot be met the code will ignore that and move onto the next line.
In the next part of the challenge you will learn to call a function which is where you pass in the actual numbers. :-)