MAth.random problem

Hi ,
please tell why i got 0 as well in output when i defined the range from 1 to 4

Hello there,

It does not look as though you saved your code.

For future posts, please do not paste a screenshot. It is difficult to work with, and you are less likely to get help this way.

Hello.
the last closed parenthesis should be after the number 1.
Like this:
console.log(Math.floor(Math.random() * 4) + 1);
But to avoid problems like that I think you can use something like this instead which does the same thing:

let math = Math.floor(Math.random() * 4) + 1;

console.log(math);

For what it’s worth, I highly recommend never using math as a variable name.

It was just a test : D

Thanks everyone,
this is very nice place for learners your help helps me to move forward without stucking to the problem.

1 Like