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

Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the

Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the result of the function to the alert method.

For example, to display the results of the Math.random() method in an alert dialog you could type this:

alert( Math.random( ) );

Bummer! Did you pass 2 numbers to the max() function. Restart

Get Help Recheck work script.js

1 function max(width, lenght) { 2 if (width > lenght) { 3 alert("The width is longer"); 4 return width; 5 } else { 6 alert("The lenght is longer"); 7 return lenght; 8 } 9 } 10 max(9,2); 11 alert(max(5,2)); /* <=== this is the answer I was given but it doesn't work here. But it does work in developer tools*/ 12 ​

The alert(max(5,2)); was the response on the help section it is what I had and the other where saying was right. Is there something I'm missing. It works on console.log but on workshop it does not. Need help.

1 Answer

Steven Parker
Steven Parker
243,656 Points

I notice a few things being done that were not asked for by the instructions:

  • the function itself issues alert messages
  • the function is called with the arguments 9 and 2 before the call inside the alert

I'd bet doing one or more of these extra things is preventing it from passing.

thanks for help. It was part of the previous code challenge. The alert boxes from previous challenge I thought I could leave in but you can not. You can only have one alert to make code work for question. I end up getting yesterday after talking to a gaming buddy. He told me to get rid the other alerts and only have one at the end of the code so that it runs code then alert, because testing check first alert box and marks wrong before finishing code. Thank you again. Just starting to learn this. I've only been learning for the last 3 weeks this is all new to me. Starting to understand a little.