-
-
Save desinas/711d73d1bb331652bc7e30bce35ebba1 to your computer and use it in GitHub Desktop.
/* | |
* 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 am doing the same task now and I had problems with it. I found your solution, tested it in Udacity, and ya - it says, the code is fine. But does it really work? For example, if I change the name of the person, everything else stays the same - but this is not right according to the directions. I am somehow confused with this task!
I was stumped as well since the && has yet to be taught. In addition, I feel they'd expect us to use the knowledge they've taught up until this quiz to solve it. There must be multiple ways to solve this quiz.
Funny that in the lesson after that one, they start explaining the && .
Still, i've written the code for that quiz, tested for every suspect and room and it works fine but when i submit, it says it's not there yet.
After that, i've searched google, bumped into this post, code is equal except in the last else but works with both ways. Still doesn't pass the quiz. Anyway, i'm going through to the next lesson.
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.
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
suspect
should use one of the provided values
- The variable
-
- The variable
weapon
should 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 whensolved
is 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
What Went Well
Feedback: Your answer passed all our tests! Awesome job!