Created
July 13, 2019 22:52
-
-
Save paulmiller3000/f753378f5e138fe21966f3b6293016dc to your computer and use it in GitHub Desktop.
Return Two Values to Function in ES6
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
const isSpaceship = (ele) => { | |
if (ele) { | |
console.log('Happy path. Ele exists.'); | |
let selectedOption = ele.options[ele.selectedIndex].text; | |
console.log(selectedOption); | |
if ( selectedOption == 'Raptor' || selectedOption == 'Viper') return { ready: true, value: selectedOption }; | |
} | |
return { ready: false }; | |
} | |
const funFunction = () => { | |
const documentStatusElement = document.getElementById('vehicle-selector'); | |
let { ready, value } = isSpaceship(documentStatusElement); | |
switch (value) { | |
case 'Raptor': | |
console.log(`value: ${value}. Plan to do The Special. But first do this thing.`); | |
break; | |
case 'Viper': | |
console.log(`value: ${value}. Plan to do The Special. But first do that thing.`); | |
break; | |
default: | |
console.log(`value: ${value}. Do this other thing.`); | |
} | |
ready == true | |
? console.log(`ready: ${ready}. Do The Special.`) | |
: console.log(`ready: ${ready}. Do this other thing.`); | |
} | |
funFunction(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment