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 trialNatsai Mutyavaviri
6,656 PointsCreate a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would l
I'm failing to produce the answer they want here. Please assist, thanks.
function max(upper, lower) {
if (upper>lower) {
return upper;
}
}
2 Answers
yk7
Full Stack JavaScript Techdegree Student 22,891 PointsHello :) your code is working locally, on my pc, but for the best practice: you need to add the else statement. I tested with your code and added the "else{...}" and it worked.
Artan Ahmeti
3,046 PointsFirst I think its good idea to make sure that both of them are numbers, then if upper is not greater than lower return lower:
function max(upper, lower) {
// make sure that upper and lower are numbers
if (isNaN(upper) || isNaN(lower)) {
console.log('upper and lower should be numbers')
return;
}
if (upper>lower) {
return upper;
}
return lower;
}