I can't figure out why the following code always goes to my else
statement, instead of my initial if
condition.
var player = {
inventory: [
"Bullet"
],
};
function use() {
alert(this); // Returns "Bullet"
alert(player.inventory); // Returns "Bullet"
if (this == player.inventory) {
document.getElementById("inventory02").innerHTML = "You USED" + this;
alert("in inventory"); // She skips this
} else {
document.getElementById("inventory02").innerHTML = "You don't have" + this;
alert("not in inventory"); // She always does this
}
}
<button id="use_bullet" onclick="use.call('Bullet')">Use Bullet</button>