Skip to content

Instantly share code, notes, and snippets.

@paulmiller3000
Created July 13, 2019 22:52
Show Gist options
  • Save paulmiller3000/f753378f5e138fe21966f3b6293016dc to your computer and use it in GitHub Desktop.
Save paulmiller3000/f753378f5e138fe21966f3b6293016dc to your computer and use it in GitHub Desktop.
Return Two Values to Function in ES6
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