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 Random Number Challenge, Part II

Casey Catron
Casey Catron
1,831 Points

Random Number Challenge, Part II - Help make me better.

http://codepen.io/ccatron/details/EjMNjy/

Always looking for insight on the challenges and working to get better. Here is my answer. Let me know your thoughts. I am about to be looking over the teachers code now. Thank you as always!

1 Answer

Hey so when you use CodePen, they do things a little differently with the HTML. You don't need to include the html, head or body tags, just whatever you would put in the body. So, it's currently returning 404 errors for the script and CSS files it can't find.

Technically, because you're doing everything in the JavaScript part and showing messages via the console, you don't even need any HTML or CSS.

As for your code, you don't need to check if the result of the isNan function is strictly equal to true, since it will already return a boolean true or false. So you can shorten the conditional to:

if (isNan(one) || isNan(two)) {
...
}

Also, thrown errors are only good as the message they communicate. Unfortunately, yours won't tell the user what the problem actually is. And while I don't have a personal issue with it, some people might take offence to the use of 'WTF'. (You probably wouldn't use this in a work scenario! :)

Lastly, it's important to note that any code that occurs after an uncaught error (like the one you've thrown in the function) won't get run/executed, so you should move your helpful alert to before the function calls.