Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save claudiainbytes/660ec03a5155de58a381e004b72c10de to your computer and use it in GitHub Desktop.
Save claudiainbytes/660ec03a5155de58a381e004b72c10de to your computer and use it in GitHub Desktop.
Murder Mystery - JS using else if
// change the value of `room` and `suspect` to test your code
var room = "ballroom";
var suspect = "Mr. Kalehoff";
var weapon = "";
var solved = false;
if ( room == "ballroom" ) {
weapon = "poison";
if (suspect == "Mr. Kalehoff"){
solved = true;
}
} else if ( room == "gallery" ) {
weapon = "trophy";
if (suspect == "Ms. Van Cleve"){
solved = true;
}
} else if ( room == "billiards room" ) {
weapon = "pool stick";
if (suspect == "Mrs. Sparr"){
solved = true;
}
} else {
weapon = "knife";
if (suspect == "Mr. Parkes"){
solved = true;
}
}
if (solved) {
document.write(suspect + " did it in the " + room + " with the " + weapon + "!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment