I'm trying to deal 8 cards randomly in jQuery, but whenever I run my code after the 8 cards are dealt the browser crashes. It says that I have a problem on line 144 in my while loop.
I made this while loop to deal eight unique random cards.

Your while loop will keep looping as long as arr.length==8 evaluates to true. Within the while loop you are not changing the number of items of arr and therefor it will keep looping forever once the number of items reaches 8.

Edit: It probably still crashes because Math.random() returns a number between 0 and 1. If you multiply this number by 8 and add 1, this number is basically always between 1 and 8, including. This domain consists of 8 integral numbers, the same as the number of elements in your array when the loop keeps looping forever. Since there are 8 numbers in your array and k is a number between 1 and 8 every time, k will always be a number that already exists in your array. Therefor it starts looping forever. If you want to deal more than 8 cards, you will have to create a function that can result in a number outside the range 1 to 8.

yes but i need a number between 1 and 8 that's the problem , unique 8 numbers
–
ziz194May 15 '13 at 20:09

@ziz194 Then there are only 8 numbers available for you. How do you want to add a 9th unique number to your array then? Because that is what you are trying to do and your script is not stopping until it succeeded (which will be never, explaining the crash).
–
Patrick KostjensMay 15 '13 at 20:12