Hey i just started to learn javascript today.
And i'm having a little bit of trouble understanding the else if statement.
I thought if the first if statement is true the other two else if statements would not be called?
And if the first if statement was false it would try the second else if statement and if the second one returned false it would try the third else if statement?
But all the statements return true and i'm not sure why and was hoping someone could explain to me why?
var Builds = [
{ dead: 0, tier: 8, type: "Stash", uid: 9989, x: 4032, y: 11424 },
{ dead: 0, tier: 1, type: "Wall", uid: 9990, x: 4042, y: 11525 },
{ dead: 0, tier: 1, type: "Wall", uid: 9991, x: 4052, y: 11526 },
{ dead: 0, tier: 0, type: "Wall", uid: 9992, x: 4062, y: 11527 },
{ dead: 0, tier: 0, type: "Door", uid: 9993, x: 4072, y: 11428 },
{ dead: 0, tier: 0, type: "Door", uid: 9994, x: 4082, y: 11429 },
{ dead: 0, tier: 8, type: "Door", uid: 9995, x: 4092, y: 11430 },
{ dead: 0, tier: 1, type: "Gun", uid: 9996, x: 4100, y: 11431 }
];
Object.keys(Builds).filter(function(e) {
return ("Stash" == Builds[e].type || "Wall" == Builds[e].type || "Door" == Builds[e].type);
}).forEach(s => {
if (Builds[s].type == "Stash") {
console.log(Builds[s].type)
} else if (Builds[s].type == "Wall") {
console.log(Builds[s].type)
} else if (Builds[s].type == "Door") {
console.log(Builds[s].type)
}
})
Sorry if my english is bad.
