Skip to content

Instantly share code, notes, and snippets.

@desinas
Last active October 23, 2024 15:32
Show Gist options
  • Save desinas/711d73d1bb331652bc7e30bce35ebba1 to your computer and use it in GitHub Desktop.
Save desinas/711d73d1bb331652bc7e30bce35ebba1 to your computer and use it in GitHub Desktop.
Murder Mystery Quiz (3-4) Udacity Lesson 12
/*
* 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 + "!");
}
@desinas
Copy link
Author

desinas commented Dec 13, 2017

What Went Well

  • Your code should have a variable room
  • Your code should have a variable suspect
  • Your code should have a variable weapon
  • Your code should have a variable solved
  • Your code should include a conditional statement
  • The variable suspect should use one of the provided values
  • The variable weapon should be based on the room
  • Your code should produce the expected output

Feedback: Your answer passed all our tests! Awesome job!

@aleksger
Copy link

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!

@hassanali2181
Copy link

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.

@tiagocostarebelo
Copy link

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.

@Cchaney24
Copy link

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.

@omar-abokhadra
Copy link

I Thing I have found the solution

`/*

  • Programming Quiz: Murder Mystery (3-4)
    */

/*

  • QUIZ REQUIREMENTS
    1. Your code should have a variables - room, suspect, weapon, and solved
    1. Your code should include a conditional statement
    1. The variable suspect should use one of the provided values
    1. The variable weapon should be based on the room
    1. 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!
    1. 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:
    1. sets the value of weapon based on the room and
    1. 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 when solved is true
      if (solved) {
      console.log(suspect+" did it in the "+room+" with the "+weapon+"!");
      } else {
      "nothing"
      }
      /
      ****************************************** */`

in last else, you should set vars (suspect and room )

@mikiyas-l
Copy link

why is the initial value false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment