(8/10)
Building A Dice Roller — JavaScript typing lesson
Create a random dice roller with JavaScript.
What you'll practice
Let's use JavaScript's built-in `Math.random()` to build a dice roller!
- `Math.random()` gives you a random number between 0 (inclusive) and 1 (exclusive).
- Multiplying by 6 makes it a number between 0 and 5.999...
Pro Access Required
This is a premium lesson. Upgrade to Pro to unlock this interactive exercise and continue your learning journey.
📜JavaScript
Building A Dice Roller
0 WPM
0% Accuracy
0:00 Time elapsed
1
2
3
4
let roll = Math.floor(Math.random() * 6) + 1;↵
↵
console.log('you roll the dice...');↵
console.log('you rolled a ' + roll);
0 / 120
Press This!
👇
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
⌫
⇥
Q
W
E
R
T
Y
U
I
O
P
[{
]}
\|
⇪
A
S
D
F
G
H
J
K
;:
'"
↵
⇧
Z
X
C
V
B
N
M
,<
.>
/?
⇧
Thumb
Index
Middle
Ring
Pinky