Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created June 17, 2012 12:23
Show Gist options
  • Select an option

  • Save ruprict/2944402 to your computer and use it in GitHub Desktop.

Select an option

Save ruprict/2944402 to your computer and use it in GitHub Desktop.
var day;
if (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday") {
do_scream();
pull_hair_out();
} else {
relax();
go_camping();
}
@ericmann

Copy link
Copy Markdown

Actually, this code is incorrect. day = "Monday" is an assignment, not an equality comparison. So (day = "Monday" || "Tuesday" || "Wednesday" || "Thursday") will assign "Monday" to day and 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 to true when you do the logical check.

The correct code snippet would be:

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