Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/83f223e33b9ffd87c246 to your computer and use it in GitHub Desktop.
Save appkr/83f223e33b9ffd87c246 to your computer and use it in GitHub Desktop.
JavaScript Ternary Operator and Assignment using Logical Operator// source http://jsbin.com/nucida
var armory = {
swords: [
"Broadsword",
"Claymore",
"Scimitar"
],
addSword: function(sword) {
this.swords = this.swords || [];
this.swords.push(sword);
},
retrieveSword: function(request) {
var index = this.swords.indexOf(request);
return index >= 0 ? this.swords.splice(index, 1)[0] : alert("No " + request + "baby !");
}
};
var armoryIsOpen = true;
var isKnight = true;
var weapon = armoryIsOpen && isKnight && armory.retrieveSword("Claymore");
console.log(weapon);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment