To generate a random number between 1 and 100 in JavaScript, you can use the Math.random()
method, which returns a value between 0 (inclusive) and 1 (exclusive). You can then multiply that value by 100 to get a number between 0 and 100, and add 1 to get a number between 1 and 100. Here's the code:
index.tsx129 chars3 lines
The Math.floor()
method rounds the result down to the nearest integer to ensure that the result is between 1 and 100 and not a decimal value.
gistlibby LogSnag