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 trialQasim Rashad
Front End Web Development Techdegree Student 7,837 Pointsneed help
It's saying it's an error in my function but can't spot it. Am I'm missing something?
function max (upper){
var max
return max;
}
1 Answer
Steven Parker
231,236 PointsThe instructions say to create a function "which accepts two numbers as arguments"*, but the function shown here takes only one argument.
The instructions also say "The function should return the larger of the two numbers", so you'll need some kind of comparision to control which argument to return.
Another hint: you won't need to create any new variables inside the function.
Qasim Rashad
Front End Web Development Techdegree Student 7,837 PointsQasim Rashad
Front End Web Development Techdegree Student 7,837 PointsIβve put
Function max (7 > 5) { Return upper;
I replaced βupperβ and added two numbers arguments, also made the return value as 7 so it know which number is greater. When I rechecked the work it popped up as error, am Iβm on the right track?
Steven Parker
231,236 PointsSteven Parker
231,236 PointsIn the definition, the function arguments are placeholders for actual values that will be supplied later when the function is invoked. They are given names which will work like variables inside the function body.
Then, any operations performed on or with them will occur in the function body.
Qasim Rashad
Front End Web Development Techdegree Student 7,837 PointsQasim Rashad
Front End Web Development Techdegree Student 7,837 PointsLIke this?
Function max (width > height) { Return width; }
Steven Parker
231,236 PointsSteven Parker
231,236 PointsNot quite. Remember I said that "any operations performed on or with them will occur in the function body". Plus, you'll need some way to return one argument or the other depending on which is larger.
It might help to look at some of the other questions asked on this same topic.
Qasim Rashad
Front End Web Development Techdegree Student 7,837 PointsQasim Rashad
Front End Web Development Techdegree Student 7,837 PointsI've figured it out it was function max (width, height) {
return height; }
Steven Parker
231,236 PointsSteven Parker
231,236 PointsI guess he challenge isn't testing very thoroughly! That should not have passed because it's still missing a comparison test and a separate return for when the other value is larger.