4
I would like to go 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 goal is to check if the chair is free and if the user is free to accept it. If accepted, the loop must be stopped.
Thanks for your help.
And what’s the problem? Apparently the code is already doing that job.
– Giancarlo Abel Giulian
The code, as it was, was not running because of the semicolon and break problems that were not being used correctly. Thank you for your comment.
– Márcio Ricardo
I hadn’t noticed. You’re welcome, I just needed to call.
– Giancarlo Abel Giulian