Randell Dawson e9212c61d2 fix(curriculum): Remove unnecessary assert message argument from English challenges JavaScript Algorithms and Data Structures - 01 (#36401)
* fix: rm assert msg basic-javascript

* fix: removed more assert msg args

* fix: fixed verbiage

Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com>
2019-07-13 08:07:53 +01:00

1.9 KiB

id, title, challengeType, videoUrl
id title challengeType videoUrl
cf1111c1c11feddfaeb9bdef Generate Random Fractions with JavaScript 1 https://scrimba.com/c/cyWJJs3

Description

Random numbers are useful for creating random behavior. JavaScript has a Math.random() function that generates a random decimal number between 0 (inclusive) and not quite up to 1 (exclusive). Thus Math.random() can return a 0 but never quite return a 1 Note
Like Storing Values with the Equal Operator, all function calls will be resolved before the return executes, so we can return the value of the Math.random() function.

Instructions

Change randomFraction to return a random number instead of returning 0.

Tests

tests:
  - text: <code>randomFraction</code> should return a random number.
    testString: assert(typeof randomFraction() === "number");
  - text: The number returned by <code>randomFraction</code> should be a decimal.
    testString: assert((randomFraction()+''). match(/\./g));
  - text: You should be using <code>Math.random</code> to generate the random decimal number.
    testString: assert(code.match(/Math\.random/g).length >= 0);

Challenge Seed

function randomFraction() {

  // Only change code below this line.

  return 0;

  // Only change code above this line.
}

After Test

(function(){return randomFraction();})();

Solution

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