JavaScript开关语句未执行案例1

JavaScript开关语句未执行案例1,javascript,Javascript,我正试图让我的代码的案例1执行,但由于某些原因,这并没有发生,我对JS相当陌生,我使用w3 school使用switch语句,但由于某些原因,它不会执行案例1,我甚至删除了中断 让问候语=字符串(提示(“输入您的姓名”); log(“你好”+问候语+“+”我希望你好”); 让问题=布尔值(提示(“输入布尔值”); 开关(问题){ 案例0: 问题==错误; log(“很高兴听到你没有生病,“+theQuestion+”); 打破 案例1: 问题==正确; log(“很遗憾听到“+theQuest

我正试图让我的代码的案例1执行,但由于某些原因,这并没有发生,我对JS相当陌生,我使用w3 school使用switch语句,但由于某些原因,它不会执行案例1,我甚至删除了中断

让问候语=字符串(提示(“输入您的姓名”);
log(“你好”+问候语+“+”我希望你好”);
让问题=布尔值(提示(“输入布尔值”);
开关(问题){
案例0:
问题==错误;
log(“很高兴听到你没有生病,“+theQuestion+”);
打破
案例1:
问题==正确;
log(“很遗憾听到“+theQuestion+”+“您病得很重”);
打破
};
让数字=数字(提示(“输入数字”));
log(“我很遗憾听到我对治疗失败感到惊讶”+

“+数字*数字+”+“美元”+“感谢上帝的保险”)它不会执行它,因为您没有向变量返回任何内容

此外,使用布尔值也不是很正确,因为如果有人写的不是true或false,那么它就不起作用了

改为使用while循环检查。 另外,如果您只是在使用该代码,请尝试使用var而不是let

你把你的情况设为0或1,这是没有意义的,因为你想知道是真是假

请尝试以下方法:

let theGreeting = String(prompt("enter your name"));
console.log("hello " + theGreeting + " " + "how are you I hope well");
let theQuestion = Boolean(prompt("enter boolean value "));

switch (theQuestion) {
case true:
theQuestion = false;
console.log("it was" + theQuestion + "that is very good to hear that you were 
not sick");
 break;

  case false:
 theQuestion = true;
 console.log("sorry to hear that it is " + theQuestion + " " + "that you were 
 very sick");
 break;

};

 let theNumber = Number(prompt("enter number"));
  console.log("I am sorry to hear that I am surprised that the treatment was" 
+ " " + theNumber * theNumber + " " + " dollars " + "thank god for 
insurance");
还有一个额外的奖励提示,用空格或制表符缩进您的代码,但请缩进它,不仅是为了我们,也是为了您的


祝你好运

theQuestion==true不是赋值,而是相等检查。将所有实例更改为
theQuestion=true
/
theQuestion=false
没有帮助我将swtich cases更改为have=not==但仍然有相同的问题检查我编辑的答案@J1N1.lol你不知道我被告知很多次我正在处理它,非常感谢你的帮助