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 trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Gilbert Torres
seal-mask
.a{fill-rule:evenodd;}techdegree
Gilbert Torres
Front End Web Development Techdegree Student 2,479 Points

Hello, My solution works on jsFiddle, but not on the challege question?

function max(fNum, sNum) { if (fNum > sNum) { return 'The first number ' + fNum + " " + "is the larger Number"; } else { return 'The second number ' + sNum + " " + "is the larger Number"; } } alert( max(5, 10) );

script.js
function max(fNum, sNum) {
         if (fNum > sNum) {
     return 'The first number ' + fNum + " " + "is the larger Number";
}   else {
     return 'The second number ' + sNum + " " + "is the larger Number";
           }
}
alert( max(5, 10) );

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great, but you've gone a little bit above and beyond what they asked for. Remember that challenges are very strict. The challenge asks you to return the largest of the two numbers. But what you're returning is a string containing the largest of the two numbers. To be fair, your output is prettier, but the challenge did not ask for a string to be returned.

:bulb: Going forward it's important to try not to do anything the challenge doesn't explicitly ask for. Even if functional outside the challenge, it can cause the challenge to fail.

Hope this helps! :sparkles:

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

We all get stuck! :thumbsup: Don't worry. It just means you're human. When I get stuck on these, I go back and read the instructions word for word. Chances are often that I've missed some silly thing. I'm printing instead of returning... that sort of thing. Hang in there! You're doing just fine :smiley: