Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this practice challenge, you will make the random number function you created earlier more flexible.
This video doesn't have any notes.
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
Now that you've learned how to define and
0:00
use functions,
I have a practice challenge for you.
0:02
I'd like you to make the random
number function you created earlier
0:05
even more flexible.
0:08
This time,
the function needs to accept two values,
0:10
a lower value and an upper value.
0:13
In other words, the function should be
able to produce random values between,
0:15
say, 10 and 100, or 9 and 78, as well
as between 1 and 6, or even 0 and 6.
0:19
Let's go over the steps for
this challenge.
0:25
To get started with this challenge,
launch the workspace with this video and
0:27
open the file random.js.
0:31
In the file, I've included
a comment that provides a high
0:34
level overview of the components of
the function you'll need to create.
0:37
I also provided the formula, or logic, for
0:41
creating a random value
between two numbers, 1 and 6.
0:43
This should look familiar,
0:47
you used this in a previous
course on JavaScript numbers.
0:48
Now, you're going to use this as
the basis for creating the function for
0:50
this challenge.
0:54
Your function should be able to produce
random values between, say, 10 and
0:55
100, or 9 and 78, as well as between 1 and
6, or even 0 and 6.
1:01
Once you're done writing the function,
make sure you test it by calling it and
1:05
passing it different values.
1:09
You can display the values
in any way you choose.
1:11
For example, in the console with
console.log, and in alert dialogue or
1:13
on the page using some of
the techniques you've learned so far.
1:17
So good luck, and in the next video,
I'll show you my solution.
1:20
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