我正在尝试执行我的代码的情况1,但由于未发生的某些原因,我对JS还是陌生的,我使用w3 school使用switch语句,但由于某些原因,它将无法执行情况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 0:
theQuestion == false;
console.log("it was" + theQuestion + "that is very good to hear that you were not sick ");
break;
case 1:
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 ");
答案 0 :(得分:0)
它不会执行,因为您没有向变量返回任何内容。
使用boolean也不是很正确,就好像有人写了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");
还有一个额外奖金提示,使用空格或制表符使您的代码缩进,但不仅为了我们,也为了您自己,都将其缩进。
祝你好运!