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 trialFrancisco Ortiz
2,673 PointsMy code should work! I'm making a conditional statement that shows that variable b will be returned if it's bigger!
Why is this not being accepted? I am calling the function and b is being returned as it is truly bigger. I mean, isn't b being returned in this function?
function max(a,b){
if(a > b){
console.log('a is smaller, therefore it will not return')
} else{
return b
};
max(a,b);
3 Answers
joelearner
54,915 PointsHi Fransisco,
You are very close to the solution. You really just need to simplify your answer and work on a syntax issue. For the syntax, you will need to close the else portion with an extra "}" closing bracket. Then, you can eliminate the call for max at the end because you will get a return with function that you have, at least according to the challenge. Your code should look something like this:
function max(a,b){
if(a > b){
console.log('a is smaller, therefore it will not return');
} else{
return b;}
};
Cheers!
Kuanyshbek Ospanov
17,416 PointsYou must return a higher variable. But there nothing you are returning
if (a>b) {
console.log('a is smaller, therefore it will not return')
}
Try this code
if (a>b) {
return a
} else {
return b
}
andrew gibbs
6,063 PointsHey Francisco, This has been addressed before, but I will give some more insight into how I would think of it. Your max function returns the largest of two numbers. The way you wrote it, you assumed that b would always be the max value. However, the possibility exists where a is the larger value and for that you need to return a since parameters into max could be for example (5,4) or (4,5) and those would have different results. Hope that helps in your thought process for future problems.
Francisco Ortiz
2,673 PointsFrancisco Ortiz
2,673 PointsI can see that I did not input any value inside the argument of the function that I am using to call the function.