Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Numbers!
You have completed JavaScript Numbers!
Preview
It's time for another programming challenge! In this challenge, you'll create a random number generator. It should collect a number from a user, then print a random number from 1 up to the user's provided number.
Challenge Instructions
- Collect a user's input.
- Convert that input from a string to a number. This will be the highest possible random number in the range of numbers starting from 1.
- Use the
Math.random()
method to create a random number using the number provided by the user. - Create a message displaying the random number. You can use any method you want to display the message. For instance, print it to the console, display it on the page, or with an alert.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Youβve learned how to work with numbers
and perform math with JavaScript.
0:00
You also learned how to
create random numbers.
0:04
I think youβre ready for
a programming challenge.
0:06
In this challenge,
youβll create a random number generator.
0:08
It should collect a number from a user
then print a random number from one
0:11
up to the user's provided number.
0:16
To get started,
launch the new workplace with this video.
0:18
In the file random.js,
0:21
I've included comments with
instructions on what you'll need to do.
0:23
You'll use some of the concepts you've
learned so far to complete this challenge.
0:26
First, you'll need to
collect a user's input,
0:31
then convert that input
from a string to a number.
0:35
This will be the highest possible
random number in the range of numbers
0:38
starting from 1.
0:42
Then use the Math.random method
0:44
to create a random number using
the number provided by the user.
0:46
Finally you'll create a message
displaying the random number.
0:51
You can use any method you
want to display the message.
0:54
For instance, printed to the console
displayed on the page or with an alert.
0:57
The goal is to get your program
to work similarly to this.
1:02
So good luck, have fun, and in the next
video, I'll show you how I did it.
1:09
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up