When you remove the found element, you are passing in a string literal instead of the variable name:
allGroundShoes.indexOf('randomAllGroundShoes');
Since there is no element 'randomAllGroundShoes'
, the element would never be found, and no elements would ever be removed from the array.
It should be:
allGroundShoes.indexOf(randomAllGroundShoes);
But, you are doing the same thing more than once. You don't need to check allGroundShoes.indexOf()
at all. You could just store the random number in a variable and reference it again. But, even that is more than you need. Just call splice()
to get your value:
randomAllGroundShoes = allGroundShoes.splice(
Math.floor(Math.random() * allGroundShoes.length), 1)[0];
$('#'+randomAllGroundShoes).addClass('shoeNegitive');
This way, you retrieve your value and remove it from the array in one step - no additional lookup required.