2018-10-08 13:34:43 -04:00

2.3 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
cf1111c1c11feddfaeb9bdef Generate Random Fractions with JavaScript Generar fracciones aleatorias con JavaScript 1

Description

Los números aleatorios son útiles para crear un comportamiento aleatorio. JavaScript tiene una función 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 completamente una Nota de 1
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

Cambie 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

function randomFraction() {
  return Math.random();
}