How to generate a 4 digit random number by JavaScript?

Please explain in detail so that I can understand the behind the scene of this kinda task. Thanks in advance

Hi! I’m not going to explain it in detail, because that’s the fun :slight_smile: but you’ll want to start with the Math.random() function, which returns a number between 0 and <1. To make that number into an integer there’s another Math function, Math.floor(), and to get it between a certain range you’ll have to do some multiplication. That should get you reasonably well-started!

I always recommend checking out the MDN docs: