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 + "!");
}
@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