我错过了什么?
在这个谋杀之谜中有:
四个房间:宴会厅,画廊,台球室和餐厅, 四种武器:毒药,奖杯,台球棒和刀, 还有四名嫌疑人:帕克斯先生,范克利夫人,斯帕尔夫人和卡勒霍夫先生。 我们也知道每件武器都对应一个特定的房间,所以......
我们知道每个嫌犯都是在谋杀发生时被安置在特定的房间里。
为了帮助解决这个谜团,请编写以下条件语句的组合:
然后,如果解决了这个谜团,请将以下内容打印到控制台:
<_> __________在__________与__________!一起做了所以我输入了以下内容
// change the value of `room` and `suspect` to test your code
var room = "dining room";
var suspect = "Mr. Parkes";
var weapon = "knife";
var solved = false;
if (room == "gallery" && suspect == "Ms. Van Cleve") {
solved = true;
weapon == "trophy";
} else if (room == "dining room" && suspect == "Mr. Parkes") {
solved = true;
weapon == "knife";
} else if (room == "billiards room" && suspect == "Mrs. Sparr") {
solved = true;
weapon == "pool stick";
} else { room == "ballroom";
suspect == "Mr. Kalehoff";
weapon == "poison";
solved = true;
}
if (solved) {
console.log(suspect + "did it in the" + room + "with the" + weapon +"!");
}
但继续
再试一次
什么不好
错在哪里
答案 0 :(得分:1)
你没有完成解决这个谜团的两个步骤。
为了帮助解决这个谜团,写一个有条件的组合 陈述:
1)根据房间设置武器的值并设置值 如果房间的价值与嫌疑人的房间匹配,则解决为真
你应该有一个if语句,如
if (room == "dining room")
{
//set weapon
}
else if (room == "ballroom")
{
//set weapon
}
else if (room == "billiards room")
{
//set weapon
}
else if (room == "gallery")
{
//set weapon
}
此外,您在else-if中的条件语句不正确。它应该是||不是&amp;&amp;
答案 1 :(得分:1)
您需要知道每个嫌疑人的有效房间以及每个房间的有效武器。
var weapons = {
'dining room': 'knife',
'ballroom': 'poison',
'gallery': 'trophy',
'billiards room': 'pool stick'
};
var rooms = {
'Mr. Parkes': 'dining room',
'Ms. Van Cleve': 'gallery',
'Mrs. Sparr': 'billiards room',
'Mr. Kalehoff': 'ballroom'
};
var suspect = "Mr. Parkes";
var solved = false;
var room = rooms[suspect];
var weapon = weapons[room];
if(room !== undefined && weapon !== undefined) {
solved = true;
}
if(solved === true) {
console.log(suspect + " did it in the " + room + " with the " + weapon + "!");
}
答案 2 :(得分:0)
var room = "dining room";
var suspect = "Mr. Parkes";
var weapon = "";
var solved = false;
if (room === "ballroom") {
weapon = "poison"; solved = suspect === "Mr. Kalehoff";
} else if (room === "gallery") {
weapon = "trophy"; solved = suspect === "Ms. Van Cleve";
} else if (room === "billiards room") {
weapon = "pool stick"; solved = suspect === "Mrs. Sparr";
} else {
weapon = "knife"; solved = suspect === "Mr. Parkes";
}
if (solved) {
console.log(`${suspect} did it in the ${room} with the ${weapon}!`);
}