Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Working With Numbers The Random Challenge

What Am I Doing Wrong Here?

The Random Challenge

Here are the instructions:

Create a Random Number Generator. Collect a number from a user with the prompt command. Print a random number from 1 to the users provided number. Use paserInt to convert the input to an integer.

I am not receiving a message as this is a challenge performed via the launched workspace.

Here is what I have so far:

var guestSelection = prompt('Please enter a single digit number?');

var topNumber = parseInt(guestSelection);

var randomNumber = Math.floor(Math.random() * topNumber) + 1;

var message = '<p> 3 is a number between 1 and 6.</p>';```

 And the read out that I am getting is simply a page titled Random Number Generator. It gives the option to place an entry within the prompt dialog box. Then nothing else happens.

What am I doing wrong? 

Thanks in advance for any assistance provided!

1 Answer

Antony .
Antony .
2,824 Points

Hello, Michelle Dobbs

Technically to print this out to the page all you would need to do is use document.write() with the variable message inside the parentheses. But to simplify your code challenge I have changed a few stuff in your code to make it better.

var guestSelection = prompt('Please enter a single digit number?');

var topNumber = parseInt(guestSelection);

var randomNumber = Math.floor(Math.random() * topNumber) + 1;

var message = '<p> ' + randomNumber + ' is a number between 1 and ' + topNumber;

document.write(message);

You can also simplify further:

var userNumber = prompt('Give me a number');
var randomness = Math.floor(Math.random() * parseInt(userNumber));
alert(randomness);
Antony .
Antony .
2,824 Points

Looking good Casey!