Why would assignment not work in code editor?

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);


what’s the challenge link?

What is the code that does not work? You should be able to return the variable randomNumberBetween0and9.

I have updated the link

Yeah that’s what I thought but the code editor wont let you pass the criteria if you try to do that. I was wondering why.

It will. I’ve done it. That’s why I asked to see what code you tried.

1 Like

Ok I tried it again and it worked first time. I have no clue why it didn’t work yesterday but thanks for your help.

My best bet is that you had a typo before. It happens a lot, especially with long variable names.