我有一个任务,用户在提示框中输入一个数字,然后月份就出来了。到目前为止,这是代码:
<script type="text/javascript">
var a = prompt("enter a month number please.");
var b = "";
switch(a){
case 1: b = "January";
break;
case 2: b = "February";
break;
case 3: b = "March";
break;
case 4: b = "April";
break;
case 5: b = "May";
break;
case 6: b = "June";
break;
case 7: b = "July";
break;
case 8: b = "August";
break;
case 9: b = "September";
break;
case 10: b = "October";
break;
case 11: b = "November";
break;
case 12: b = "December";
break;
}
if((a==12) || (a==1) || (a==2)){
document.write(" It is " + a + ", which is in winter.")
}
if((a==3) || (a==4) || (a==5)){
document.write(" It is " + a + ", which is in spring.")
}
if((a==6) || (a==7) || (a==8)){
document.write(" It is " + a + ", which is in summer.")
}
if((a==9) || (a==10) || (a==11)){
document.write(" It is " + a + ", which is in fall.")
}
</script>
我的月不是输出。相反,数字是我的输出。似乎我的 switch 语句被忽略了,只做 if 语句。我迷失在我做错了什么。