I'd like to loop through a two-dimensional array according to the code:
var cadeiras = [[true, false, true, true, true, false, false, true, true, true, false, false],
[true, false, true, true, true, false, false, true, true, true, false, false],
[true, false, true, true, true, false, false, true, true, true, false, false],
[true, false, true, true, true, false, false, true, true, true, false, false]];
for (i = 0, i < cadeiras.length, i++){
for (j = 0, j < cadeiras[i].length; j++) {
if([i][j]){
var reserva = confirm("A cadeira " + (j+1) + " na fila " + (i+1) + " está disponível. Deseja reservá-la?");
if(reserva){
document.getElementById("assento" + numeroCadeira).src = "img/cadeira-tulipa-reservada.jpg"
document.getElementById("assento" + numeroCadeira).alt = "reservada"
document.getElementById(numeroCadeira).classList.remove("panel-default");
document.getElementById(numeroCadeira).classList.add("panel-success");
alert("A cadeira " + (j+1) + " na fila " + (i+1) + " está reservada.");
break;
}
}
}
}
The purpose is to check if the chair is free and if it is free give the user the option to accept it. If it is accepted, the loop should be interrupted.
Thanks in advance for the help.