I have try to make the random number for code in this form using snippet in chrome
var n = Math.random();
n = n * 6;
Math.floor(n) + 1;
but when i try to make it shorter like this
var n = Math.floor(Math.random() * 6) + 1;
seem like it won’t work for me (undefined), but again I have seperated like this
var n = Math.random();
n = Math.floor(n * 6) + 1;
It kinda work. What is the problem of the shorter form for this code?
2
Answers
var n = 6;
if you run this code on browser console, it print the return value of = operator and it is undefined.
Welcome to stackoverflow.
Please try to add put your code in the code snippet element.
Like this:
And here your second code:
As you can see, both are working like expected.