Here is the portion of the code that is in question:
var seats = [false, true, false, true, true, true, false, false, false];
function initSeats() {
for (var i = 0; i < seat.length; i++) {
if (seats) {
//Sets the seat to available
document.getElementById("seat" + i).src = "seat_avail.png";
document.getElementById("seat" + i).alt = "Available Seat";
}
else
//Sets the seat to unavailable
document.getElementById("seat" + i).src = "seat_unavail.png";
document.getElementById("seat" + i).alt = "Unavailable Seat";
}
}
}
-------------
Essentially the function is to loop through the array and display images in the body respective to what their index is.
MY QUESTION IS:
How does the seat array in the condition: if (seat) { etc., etc... equal to true?
I would understand if the condition read: if (seat == true) { etc., etc., but the way it is currently written I just don't understand.
I mean, how does that mean that the array it hits is true and brings up the seat_avail.png image and sets the seat to "available"? I just don't understand how the code reads for that specific condition to mean true in this situation. Any help would be greatly appreciated, because I'm racking my brain and feeling like a complete idiot right now!
Thank you in advance!
var seats = [false, true, false, true, true, true, false, false, false];
function initSeats() {
for (var i = 0; i < seat.length; i++) {
if (seats) {
//Sets the seat to available
document.getElementById("seat" + i).src = "seat_avail.png";
document.getElementById("seat" + i).alt = "Available Seat";
}
else
//Sets the seat to unavailable
document.getElementById("seat" + i).src = "seat_unavail.png";
document.getElementById("seat" + i).alt = "Unavailable Seat";
}
}
}
-------------
Essentially the function is to loop through the array and display images in the body respective to what their index is.
MY QUESTION IS:
How does the seat array in the condition: if (seat) { etc., etc... equal to true?
I would understand if the condition read: if (seat == true) { etc., etc., but the way it is currently written I just don't understand.
I mean, how does that mean that the array it hits is true and brings up the seat_avail.png image and sets the seat to "available"? I just don't understand how the code reads for that specific condition to mean true in this situation. Any help would be greatly appreciated, because I'm racking my brain and feeling like a complete idiot right now!
Thank you in advance!