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 trialDavid Marín
1,916 PointsI am stuck here, anyone could help me? Thanks!
I have been trying differents options but I don't find the right answer... I am made a mess :(
function max(upper){
}
5 Answers
Nicholas Vogel
12,318 PointsThe challenge says you need two parameters, an upper and a lower.
function max(upper, lower) {
}
David Marín
1,916 PointsThank you I got it!
David Marín
1,916 Pointsfunction max (upper, lower){ var lower; var upper; if(lower < upper){ return upper; } else { return lower; } }
max()
I did it :D
Nicholas Vogel
12,318 PointsGreat job!
Simon Coates
28,694 Pointsmy solution was
function max(first, second) {
if(first>second) {
return first;
}
return second;
}
alert(max(4, 3));
I;m not sure about your declaring variables. I don't know what it does. initially, i thought declaring your variable might interfere with your parameters. But it seems to work. Hence i'm curious if it alters anything (?).
David Marín
1,916 Pointsfunction max (upper, lower){ var lower = 1; var upper = 100; if(lower < upper){ return upper; } else { return lower; } }
I have been using this code in the console of chrome. You can change the numbers of the variables for know which number is greater than the other. For this reason I have used variables.
Do you understand?
Simon Coates
28,694 Pointsbut parameters are already variables. You could overwrite the parameter values without using the var keyword:
function max(first, second) {
first = 45;
second = 89;
if(first>second) {
return first;
}
return second;
}
alert(max(4, 3));
David Marín
1,916 PointsTrue! I did not know it! Great, Thank you! :)
Simon Coates
28,694 PointsSimon Coates
28,694 PointsCan you post an attempt? Or could you confirm that you want the full answer? In terms of a learning experience, it might be more beneficial to post an attempt, and get feedback. FYI, Nicholas Vogel is right about the method signature. You just need to use an if statement and two return statements. Don't need an else, as anything outside an if that includes a return statement is implicitly an else.