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 + "!"); | |
| } |
I Thing I have found the solution
`/*
- Programming Quiz: Murder Mystery (3-4)
*/
/*
- QUIZ REQUIREMENTS
-
- Your code should have a variables -
room,suspect,weapon, andsolved
- Your code should have a variables -
-
- Your code should include a conditional statement
-
- The variable
suspectshould use one of the provided values
- The variable
-
- The variable
weaponshould be based on theroom
- The variable
-
- Your code should produce the expected output: __________ did it in the __________ with the __________!
- Example: Mr. Parkes did it in the dining room with the knife!
-
- For unmatching combination of the suspect and the room, print nothing on the console
*/
- For unmatching combination of the suspect and the room, print nothing on the console
/* ****************************************** /
/ TESTING LOGIC */
// Change the value of room and suspect to 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;
/*
- To help solve this mystery, write a combination of conditional statements that:
-
- sets the value of weapon based on the room and
-
- sets the value of solved to true if the value of room matches the suspect's room
/
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 whensolvedis true
if (solved) {
console.log(suspect+" did it in the "+room+" with the "+weapon+"!");
} else {
"nothing"
}
/ ****************************************** */`
- sets the value of solved to true if the value of room matches the suspect's room
in last else, you should set vars (suspect and room )
why is the initial value false
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the help. My mistakes are always syntax. I was assuming since they already supplied the var's in the information, then I didnt have to retype them. And I added the bottom portion in my code along with the body.