Created
November 29, 2016 06:26
-
-
Save EQuimper/eac1ffb1626da70b4fb7a849a9a7f4fd to your computer and use it in GitHub Desktop.
Object literal for replace switch
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
function getDrink (type) { | |
var drinks = { | |
'coke': 'Coke', | |
'pepsi': 'Pepsi', | |
'lemonade': 'Lemonade', | |
'default': 'Default item' | |
}; | |
return 'The drink I chose was ' + (drinks[type] || drinks['default']); | |
} | |
var drink = getDrink('coke'); | |
// The drink I chose was Coke | |
console.log(drink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment