ultimate course replace switch with object

Solutions on MaxInterview for ultimate course replace switch with object by the best coders in the world

showing results for - "ultimate course replace switch with object"
Martin
06 Apr 2016
1function getDrink (type) {
2  var drinks = {
3    'coke': 'Coke',
4    'pepsi': 'Pepsi',
5    'lemonade': 'Lemonade',
6    'default': 'Default item'
7  };
8  return 'The drink I chose was ' + (drinks[type] || drinks['default']);
9}
10
11var drink = getDrink('coke');
12// The drink I chose was Coke
13console.log(drink);
14
Sara
30 Sep 2017
1{(() => {
2    switch (header) {
3                        case "Name":  return entry.name;
4                        case "Type": return entry.type;
5                        default: return entry.name;
6                    }
7})()}