samedi 28 mars 2020

How can I print a string based on a boolean variable? JavaScript

I'm having trouble finding online how to use the variable I set as a boolean: var solved = false. As you can see I'm setting the boolean as false at first. But then, when I open the IF and ELSE IF, If the two conditions are met, the boolean becomes true: solved = true. What I want to know is how to use that new value of the boolean (true) to print a response with this setup:

if (solved) {
   console.log(suspect + " did it in the " + room + " with the " + weapon);
}

Or well if thats all wrong, then can you tell how to do it please!

CODE

var weapon = "";
var solved = false;

if ((room = "dining room") && (suspect = "Mr. Parkes")){
    weapon = "knife";
    solved = true;
} else if ((room = "gallery") && (suspect = "Ms. Van Cleve")) {
    weapon = "trophy";
    solved = true;
} else if ((room = "billiards room") && (suspect = "Mrs. Spark")) {
    weapon = "pool stick";
    solved = true;
} else if ((room = "ballroom") && (suspect = "Mr.Kalehoff")) {
    weapon = "poison"
    solved = true
} else {
    console.log("Wrong suspect or room");
}

if (solved) {
    console.log(suspect + " did it in the " + room + " with the " + weapon);
}

Aucun commentaire:

Enregistrer un commentaire