Hi I need to generate a random number in JavaScript between 15 and 225 that can only be by increments of 30. For example: 45, 75, 105 etc.
Any ideas on how this can be done? I’m aware of Math.floor(Math.random()*11) for example for a random number 1-10 but how can this be modified to fit in with what I’m trying to do?
You need to think about the final outcome that you want. Between 15 and 225 is what you want to aim for, but not what you need to be working with to get the result.
225/30 = 7.5. 15 is half of 30. Therefore, (225-15)/30 = 7. You want a random number between 1 and 7, which you will then multiply by 30 and add 15 to the final result.