Let the power of modular arithmetic help you!
This function does what you want using the modulo operator:
function generate(nb) {
rnd = Math.round(Math.random())
return 1 + (nb + rnd) % 3
}
If you want to avoid calling the function, you can insert the code.
source
share