'm trying to create a function that will continuously loop through an array and check if there are still elements with a certain value. If there are no more of these elements, then I would like the function to execute a certain action.
I'm checking for '0'. If nothing is ='0', then i want to display an image. Here's what I have, any suggestions?
function partiewin()
// On verifie si il y a encore des cases avec pour valeur '0' et si non, on fini la partie
{
var found=false;
for (i=1; i <= hauteur; i++)
{
for (j=1;j <= largeur; j++)
{
if( decor[i][j]!=0)
{
window.alert("You win");
found=1;
}
}
}
if(!found)
{
}
}
This is the array
var decor = new Array(hauteur);
for (i=0; i <= hauteur; i=i+1)
{
decor[i] = new Array(largeur);
}
The array is a long list of this shape :
decor[1][1] = '24'; decor[1][2] = '21'; decor[4][8]='0' ; etc
Shouldn't this work? I'm not getting any alerts or any answer whatsoever once all the '0' are technically gone from the map..