Advertisement
728x90
You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,
javascript
1Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
2
3Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100Note: Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)
Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 65
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
150of476