Last active
August 29, 2015 14:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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