Last active
October 23, 2024 15:32
-
-
Save desinas/711d73d1bb331652bc7e30bce35ebba1 to your computer and use it in GitHub Desktop.
Murder Mystery Quiz (3-4) Udacity Lesson 12
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
| /* | |
| * Programming Quiz: Murder Mystery (3-4) | |
| */ | |
| // change the value of `room` and `suspect` to test your code | |
| var room = "dining room"; | |
| var suspect = "Mr. Parkes"; | |
| var weapon = ""; | |
| var solved = false; | |
| if (room === "ballroom" && suspect === "Mr. Kalehoff") { | |
| weapon = "poison"; solved = true; | |
| } else if (room === "gallery" && suspect === "Ms. Van Cleve") { | |
| weapon = "trophy"; solved = true; | |
| } else if (room === "billiards room" && suspect === "Mrs. Sparr") { | |
| weapon = "pool stick"; solved = true; | |
| } else { | |
| weapon = "knife"; solved = true; | |
| } | |
| if (solved) { | |
| console.log(suspect + " did it in the " + room + " with the " + weapon + "!"); | |
| } |
why is the initial value false
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I Thing I have found the solution
`/*
*/
/*
room,suspect,weapon, andsolvedsuspectshould use one of the provided valuesweaponshould be based on theroom*/
/* ****************************************** /
/ TESTING LOGIC */
// Change the value of
roomandsuspectto test your code// A room can be either of - dining room, gallery, ballroom, or billiards room
var room = "ballroom";
// A suspect can be either of - Mr. Parkes, Ms. Van Cleve, Mrs. Sparr, or Mr. Kalehoff
// Test your code by giving matching as well as unmatching names of the suspect
var suspect = "Mr. Kalehoff";
/* ****************************************** */
/* IMPLEMENTATION LOGIC*/
// Initial values
var weapon = "";
var solved = false;
/*
/
if (room == "ballroom" && suspect == "Mr. Kalehoff") {
solved = true;
weapon = "poison";
} else if (room == "gallery" && suspect == "Ms. Van Cleve") {
solved = true;
weapon = "trophy";
} else if (room == "billiards room" && suspect == "Mrs. Sparr") {
solved = true;
weapon = "pool stick";
} else {
solved = true;
weapon = "knife";
suspect = "Mr. Parkes";
room = "dining room";
}
/ ****************************************** /
// The code below will run only when
solvedis trueif (solved) {
console.log(suspect+" did it in the "+room+" with the "+weapon+"!");
} else {
"nothing"
}
/ ****************************************** */`
in last else, you should set vars (suspect and room )