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 trialRoscoe Coney
13,124 PointsChallenge Having Diff4iculty
The Question asks:
Challenge Task 1 of 2
Create a new function named max() which accepts two numbers as arguments. The function should return the larger of the two numbers. You'll need to use a conditional statement to test the 2 numbers to see which is the larger of the two.
What I have so far.
function max(num1, num2) {
if (parseInt(num1) > parseInt(num2)){
return true
} else {
return false;
}
}
console.log (max (4,5) );
2 Answers
Chris Shaw
26,676 PointsHi Roscoe,
You have a couple of problems in your code.
While not a direct problem that would cause an error you don't need to use
parseInt
since the function is already expecting anNumber
for both parameter values.Once you've completed the comparison you then need to return the number instead of a
Boolean
.
function max(num1, num2) {
if (num1 > num2){
return num1
} else {
return num2;
}
}
Jason Anello
Courses Plus Student 94,610 PointsHi Roscoe,
The function should return the larger of the two numbers. You're currently returning a boolean value.
So you need to either return num1
or num2
depending on how they compare.