2.2 KiB
2.2 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
cf1111c1c11feddfaeb9bdef | Generate Random Fractions with JavaScript | 1 | Generar fracciones aleatorias con JavaScript |
Description
Math.random()
que genera un número decimal aleatorio entre 0
(incluido) y no hasta 1
(exclusivo). Por Math.random()
tanto, Math.random()
puede devolver un 0
pero nunca devolver una 1
Nota Al igual que el almacenamiento de valores con el operador igual , todas las llamadas de función se resolverán antes de que se ejecute la
return
, por lo que podemos return
el valor de la función Math.random()
. Instructions
randomFraction
para devolver un número aleatorio en lugar de devolver 0
. Tests
tests:
- text: <code>randomFraction</code> debería devolver un número aleatorio.
testString: 'assert(typeof randomFraction() === "number", "<code>randomFraction</code> should return a random number.");'
- text: El número devuelto por <code>randomFraction</code> debe ser un decimal.
testString: 'assert((randomFraction()+""). match(/\./g), "The number returned by <code>randomFraction</code> should be a decimal.");'
- text: Debería estar usando <code>Math.random</code> para generar el número decimal aleatorio.
testString: 'assert(code.match(/Math\.random/g).length >= 0, "You should be using <code>Math.random</code> to generate the random decimal number.");'
Challenge Seed
function randomFraction() {
// Only change code below this line.
return 0;
// Only change code above this line.
}
After Test
console.info('after the test');
Solution
// solution required