A Pen by ClaudiaInBytes on CodePen.
Created
August 20, 2017 20:49
-
-
Save claudiainbytes/660ec03a5155de58a381e004b72c10de to your computer and use it in GitHub Desktop.
Murder Mystery - JS using else if
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
// 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