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
This video covers one solution to the random number challenge.
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
In the random.js file, the first step
is collecting a number from a user.
0:00
So I started by declaring a variable and
0:01
storing input from
the user in the variable.
0:04
You learned that the prompt
method returns a string,
0:06
even if someone types
a number into the dialog box.
0:09
So the value of inputHigh needed to
be converted into a number type.
0:12
I used the parseInt method to do that,
and I stored the number value in
0:17
a variable named highNumber to represent
the highest possible random number.
0:21
With this, I was able to
generate a random number from 1
0:26
to whatever the user typed in.
0:29
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