【发布时间】:2015-07-13 20:08:22
【问题描述】:
虽然我的代码在技术上正在运行,但我在测试游戏时输入的任何内容都没有给我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;
};
【问题讨论】:
-
kind、smart 和brave 总是设置为true(初始化为true 并且永远不会改变)所以只有if 会被使用。我假设根据您想要将其中一个更改为 false 的个性,然后将使用 else。
标签: javascript