Created
June 17, 2012 12:23
-
-
Save ruprict/2944402 to your computer and use it in GitHub Desktop.
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
| var day; | |
| if (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday") { | |
| do_scream(); | |
| pull_hair_out(); | |
| } else { | |
| relax(); | |
| go_camping(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, this code is incorrect.
day = "Monday"is an assignment, not an equality comparison. So(day = "Monday" || "Tuesday" || "Wednesday" || "Thursday")will assign "Monday" todayand then evaluate to true for all cases.Also, the or statements aren't checking anything.
if ("Tuesday") {}will always execute since the string "Tuesday" is converted totruewhen you do the logical check.The correct code snippet would be: