I am not getting the code, we have to generate random numbers from 0 to 1 in decimal numbers. Then why we declare result =0
while(result ===0) {
result = Math.random();
}
In my view we have to write the code like this
while(result !=0){
result = Math.random();
}
the condition of the while tests true because result === 0.
result is assigned a new value by Math.random() which can be any number greater than or equal to 0 and less than 1.
if Math.random() returns 0 then the while runs again but if Math.random() returns anything but 0 the while breaks and the return result is executed.
Your solution also works.
As long as you use Math.random and set a condition to return any number but 0 you will pass the tests. I won’t even try to think about how many possible solutions can be created that will work.