PDA

View Full Version : Javascript causing browser to become unresponsive?


Suuds2200
03-20-2009, 09:47 PM
Well , here's a clip of my code:


for (i=0;i<=11;i++)
{


var random=Math.floor(Math.random()*19);
holder[i] = fourthc[random];
while(holder[i]=="null")
{

random=Math.floor(Math.random()*19);
holder[i] == fourthc[random];

}

fourthc[random] = "null";

}


Basically what it is supposed to do is take a random number between 1 and 18 and set it to null. Then it takes another random number. If it is the same one as before it changes it to another random number between 1 and 18 until it finds a new one. The end result should be 11 random numbers between 1 and 18 with no repeats. When I run this however, my browser (safari) becomes unresponsive due to a "slow script". Anyone know what I did wrong?

Clueful
03-20-2009, 10:37 PM
The immediate problem is this line
holder[i] == fourthc[random];which has no effect and makes the loop iterate forever.