Created
January 19, 2017 16:14
-
-
Save rphuber/b13c6fd6b33926acb532ada56da10430 to your computer and use it in GitHub Desktop.
Switch vs if statement evaluation
This file contains hidden or 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
if ((num % 3 === 0) && (num % 5 === 0)){ | |
return 'fizzbuzz' | |
} else if (num % 3 === 0) { | |
return 'fizz' | |
} else if (num % 5 === 0) { | |
return 'buzz' | |
} else if (typeof num === 'number'){ | |
return num | |
} else { | |
return false | |
} | |
switch (num) { | |
case ((num % 3 === 0) && (num % 5 === 0)): | |
return 'fizzbuzz' | |
case (num % 3 === 0): | |
return 'fizz' | |
case (num % 5 === 0): | |
return 'buzz' | |
case (typeof num === 'number'): | |
return num | |
default: | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.