Continuing the discussion from freeCodeCamp Challenge Guide: Generate Random Whole Numbers with JavaScript:
Disclaimer: The forum does not allow me to link this resource for some reason so I removed the “camp” from freecodecamp. To access the resource for further context just add it back
In the above challenge, the solution is such that the return value has to be changed to Math.floor(Math.random() * 10);
. However, this value (in my attempt) is already assigned to the variable randomNumberBetween0and9. It won’t pass me if I try to return the variable but it will work with the math functions. Why is this? Is it just because I was not following the criteria and it would work on a normal code editor or is it to do with something else (only thing I can think of is something to do with local/global scope).
My attempt:
var randomNumberBetween0and19 = Math.floor(Math.random() * 20);
function randomWholeNum() {
// Only change code below this line
var randomNumberBetween0and9 = Math.floor(Math.random() * 10);
return Math.floor(Math.random() * 10);
}
randomWholeNum()