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

Creating Random Number - Javascript

So I'm a little stumped, I don't see anything wrong in my code.. I'm no getting any errors in the developer tool section when I run the application however, the application does run with the message but at the end where the number is supposed to be it just says NaN. So annoying, I bet it's a really simple fix to.. here is the code:

console.log("Start program"); var dieRoll = Math.floor( Math.round()* 6)+1; alert("Here is your random number " + dieRoll); console.log("End program");

1 Answer

You are confusing random with round.

Math.floor(Math.random() * 6) + 1

Math.round is just variation of Math.floor.

**Further explanation

Since your Math.round() didn't take any argument it produces NaN which is Not a Number.

Any arithmetic operation followed by NaN produces NaN. So that's why you were getting NaN.

lol I can't believe I didn't spot that, thank you!

I didn't even know until I typed your code. Psychology is funny

How did you get that text editor screenshot in the comment section?? I've been trying to figure that out.

It is actually built in comment box.

wrap your code with three backticks (```) you can give arguments such as JavaScript, Python etc... or file name then that file name will appear.

Look for markdown cheatsheet below the comment box