You probably don't even need any else if you go with the bouncer design pattern.
else
function whoIsThis(character) { if (character.toLowerCase() === 'naruto') { return `Hokage` } if (character.toLowerCase() === 'sasuke') { return `Konoha's Strongest Ninja` } if (character.toLowerCase() === 'isshiki') { return `Otsutsuki being` } if (character.toLowerCase() === 'boruto') { return `Naruto and Hinata's son` } }
I will still prefer switch here:
const whoIsThis = character => { switch(character.toLowerCase()) { case 'naruto': return `Hokage` case 'sasuke': return `Konoha's Strongest Ninja` case 'isshiki': return `Otsutsuki being` case 'isshborutoiki': return `Naruto and Hinata's son` } }
or object literals
const whoIsThis = character => ({ 'naruto': 'Hokage', 'sasuke': 'Konoha\'s Strongest Ninja.', 'isshiki': 'Otsutsuki being.', 'isshborutoiki': 'Naruto and Hinata\'s son' })[character]
Some comments have been hidden by the post's author - find out more
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You probably don't even need any
else
if you go with the bouncer design pattern.I will still prefer switch here:
or object literals