Last active
January 4, 2016 00:49
-
-
Save jczaplew/8544586 to your computer and use it in GitHub Desktop.
If/else
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
if (something === something) { | |
if (somethingelse === somethingelse) { | |
// somethingelse equals somethingelse | |
} else { | |
// somethingelse isn't equal to somethingelse | |
} | |
} else { | |
// something doesn't equal something | |
} | |
// What you had was... | |
if (a === b) { | |
// do something | |
} | |
if (c === d) { | |
// do something else | |
} | |
// in that case, two separate things will happen | |
// This is what you originally had | |
var compare = function(choice1, choice2) { | |
if (choice1 === choice2) { | |
return("The result is a tie!"); | |
} | |
if (choice1 === "rock") { | |
if (choice2 === "scissors") { | |
return("Rock wins!"); | |
} else { | |
return("Paper wins!"); | |
} | |
} | |
// Now we have | |
var compare = function(choice1, choice2) { | |
if (choice1 === choice2) { | |
return("The result is a tie!"); | |
} else if (choice1 === "rock") { | |
if (choice2 === "scissors") { | |
return("Rock wins!"); | |
} else { | |
return("Paper wins!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let's clean it up a bit