diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-with-javascript.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-with-javascript.md index 6795eb05641..df5743e2d44 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-with-javascript.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-with-javascript.md @@ -9,23 +9,25 @@ dashedName: generate-random-whole-numbers-with-javascript # --description-- -It's great that we can generate random decimal numbers, but it's even more useful if we use it to generate random whole numbers. +You can generate random decimal numbers with `Math.random()`, but sometimes you need to generate random whole numbers. The following process will give you a random whole number less than `20`: -
  1. Use Math.random() to generate a random decimal.
  2. Multiply that random decimal by 20.
  3. Use another function, Math.floor() to round the number down to its nearest whole number.
+1. Use `Math.random()` to generate a random decimal number. +2. Multiply that random decimal number by `20`. +3. Use `Math.floor()` to round this number down to its nearest whole number. -Remember that `Math.random()` can never quite return a `1` and, because we're rounding down, it's impossible to actually get `20`. This technique will give us a whole number between `0` and `19`. +Remember that `Math.random()` can never quite return a `1`, so it's impossible to actually get `20` since you are rounding down with `Math.floor()`. This process will give you a random whole number in the range from `0` to `19`. -Putting everything together, this is what our code looks like: +Putting everything together, this is what your code looks like: ```js Math.floor(Math.random() * 20); ``` -We are calling `Math.random()`, multiplying the result by 20, then passing the value to `Math.floor()` function to round the value down to the nearest whole number. +You are calling `Math.random()`, multiplying the result by 20, then passing the value to `Math.floor()` to round the value down to the nearest whole number. # --instructions-- -Use this technique to generate and return a random whole number between `0` and `9`. +Use this technique to generate and return a random whole number in the range from `0` to `9`. # --hints-- @@ -47,7 +49,7 @@ You should use `Math.random` to generate a random number. assert(code.match(/Math.random/g).length >= 1); ``` -You should have multiplied the result of `Math.random` by 10 to make it a number that is between zero and nine. +You should have multiplied the result of `Math.random` by 10 to make it a number in the range from zero to nine. ```js assert( @@ -74,9 +76,6 @@ assert(code.match(/Math.floor/g).length >= 1); ```js function randomWholeNum() { - - // Only change code below this line - return Math.random(); } ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range.md index d8e528a91a8..f9d999395ac 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/generate-random-whole-numbers-within-a-range.md @@ -9,11 +9,11 @@ dashedName: generate-random-whole-numbers-within-a-range # --description-- -Instead of generating a random whole number between zero and a given number like we did before, we can generate a random whole number that falls within a range of two specific numbers. +You can generate a random whole number in the range from zero to a given number. You can also pick a different lower number for this range. -To do this, we'll define a minimum number `min` and a maximum number `max`. +You'll call your minimum number `min` and your maximum number `max`. -Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing: +This formula gives a random whole number in the range from `min` to `max`. Take a moment to read it and try to understand what this code is doing: ```js Math.floor(Math.random() * (max - min + 1)) + min @@ -21,7 +21,7 @@ Math.floor(Math.random() * (max - min + 1)) + min # --instructions-- -Create a function called `randomRange` that takes a range `myMin` and `myMax` and returns a random whole number that's greater than or equal to `myMin`, and is less than or equal to `myMax`, inclusive. +Create a function called `randomRange` that takes a range `myMin` and `myMax` and returns a random whole number that's greater than or equal to `myMin` and less than or equal to `myMax`. # --hints-- @@ -87,9 +87,7 @@ for(var i = 0; i < 100; i++) { ```js function randomRange(myMin, myMax) { - // Only change code below this line return 0; - // Only change code above this line } ```