min
e um número máximo max
. Aqui está a fórmula que vamos usar. Tome um momento para lê-lo e tente entender o que este código está fazendo: Math.floor(Math.random() * (max - min + 1)) + min
randomRange
que randomRange
um intervalo myMin
e myMax
e retorne um número aleatório que seja maior ou igual a myMin
e seja menor ou igual a myMax
, inclusive. randomRange
deve ser igual ao seu número mínimo, myMin
.'
testString: 'assert(calcMin === 5, "The lowest random number that can be generated by randomRange
should be equal to your minimum number, myMin
.");'
- text: 'O maior número aleatório que pode ser gerado por randomRange
deve ser igual ao seu número máximo, myMax
.'
testString: 'assert(calcMax === 15, "The highest random number that can be generated by randomRange
should be equal to your maximum number, myMax
.");'
- text: 'O número aleatório gerado por randomRange
deve ser um inteiro, não um decimal.'
testString: 'assert(randomRange(0,1) % 1 === 0 , "The random number generated by randomRange
should be an integer, not a decimal.");'
- text: randomRange
deve usar myMax
e myMin
e retornar um número aleatório no seu intervalo.
testString: 'assert((function(){if(code.match(/myMax/g).length > 1 && code.match(/myMin/g).length > 2 && code.match(/Math.floor/g) && code.match(/Math.random/g)){return true;}else{return false;}})(), "randomRange
should use both myMax
and myMin
, and return a random number in your range.");'
```