Use a combination of Math.floor() and Math.random().

This simple one line of code will return you a number between 1 and 6 (both included):

Math.floor(Math.random() * 6 + 1)

There are 6 possible outcomes here: 1, 2, 3, 4, 5, 6.


Download my free JavaScript Beginner's Handbook!


Check out my in-depth, practical Web Development Courses!

(all 50% off with the coupon code POSITIVEVIBRATIONS)

⤴️⤴️⤴️

And signup to my upcoming JavaScript Bootcamp!

⤴️⤴️⤴️