虽然我的代码在技术上运行,但在测试游戏时我输入的内容都没有给出else
答案。有人可以看看它给我一个线索吗?
此处:
var user = prompt("How cool are you?");
var kind = true;
var smart = true;
var brave = true;
switch(user) {
case 'Pretty cool':
var personality = prompt("Are you kind or smart or brave (yes or no)?");
if(kind || smart || brave)
{console.log("Great.");}
else
{console.log("Hmm...");}
break;
case 'Cooler than ice':
var personality = prompt("Are you kind and smart and brave (yes or no)?");
if (kind && smart && brave)
{console.log("Prove it!");}
else
{console.log("Are you serious?");}
break;
case 'Not cool at all':
var personality = prompt("Are you kind or smart or brave (yes or no)?");
if (kind || smart || brave)
{console.log("I'm sure that's not true!");}
else
{console.log("Well, I'm sure you have some good qualities.");}
break;
default:
console.log("Well?");
break;
};
答案 0 :(得分:0)
从
更改if
if (kind && smart && brave)
到
if(personality)
答案 1 :(得分:0)
你应该说:
var personality = prompt("Are you kind or smart or brave (enter: kind, brave or smart)?");
if(personality == kind ||personality == smart ||personality == brave)
{
console.log("Great.");
}
else
{
console.log("Hmm...");
}
break;