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 trialTrace Harris
Python Web Development Techdegree Graduate 22,065 Pointstrying to create a function that returns the higher argument
so I am getting an error can someone point me to my error trying to make a function that allows two numerical arguments and returns the larger argument
function max( less, more ); {
if(less > more)
return less;
} else {
return more;
}
3 Answers
Luciano Bruzzoni
15,518 PointsHello, your logic is good, you just have a couple of typos.
the ; after the function's parameter should not be there, and you forgot to open a bracket after the if statement, and you are missing a close bracket at the end.
should be something like this:
function max( less, more ) {
if(less > more){
return less;
} else {
return more;
}
}
good luck!
Trace Harris
Python Web Development Techdegree Graduate 22,065 Pointsawesome thank you for your quick reply
geoffrey
28,736 PointsYou could do that as well, It's called a conditional ternary operator.
function max( less, more ) {
return (less>more) ? less : more;
}
The logic involved is the same as the code you typed, but in one line. If less is bigger than more, then return less, otherwise more.
Trace Harris
Python Web Development Techdegree Graduate 22,065 PointsTrace Harris
Python Web Development Techdegree Graduate 22,065 Pointsthankyou so much!
Luciano Bruzzoni
15,518 PointsLuciano Bruzzoni
15,518 PointsAnytime, glad you got it :)