Why I get the error:
Uncaught TypeError: Cannot read property 'indexOf' of undefined
According to the idea, the code should return the weapon or write that it does not exist, if there is no such in the swords array
var armory = {}; var swords = ["broadsword", "Katana", "Claymore", "Scimitar"]; armory.retrieveSword = function (request) { return (this.swords.indexOf(request) >= 0) ? this.swords.splice(this.swords.indexOf(request), 1)[0] : console.log("No " + request + ", baby"); }; var isKnight = true; var weapon = isKnight && armory.retrieveSword("Katana"); console.log(weapon);
var swords = ...->armory.swords = ...- Igorthis.swords == undefined. But why it is so - from your code is not clear - Kromster