[Solved] Why does Math.floor(Math.random()) function always return “0”?


This line almost always return 0 and that is why it does not get into the while.

var randomNumber = Math.floor(Math.random());

Math.random() return float values lower than 1 starting from 0 … and with Math.floor you are getting the int part which indeed is 0

1

solved Why does Math.floor(Math.random()) function always return “0”?