我似乎无法运行一个相对简单的开关盒计算器,请你纠正我的错误 我提出的提示没有出现。
<html>
<body>
<script language = "javascript">
var x;
var a = 12;
var b = 20;
x= parseInt(prompt("Enter your Choice"));
switch(x)
{
Case 1 : document.write("The Sum is : ",a+b);
break;
Case 2 : document.write("The Difference is : ",a-b);
break;
Case 3 : document.write("The Product is : ",a*b);
break;
Case 4 : document.write("The quotient is : ",a/b);
break;
default : document.write("Invalid Choice");
break;
}
</script>
</body>
</html>
答案 0 :(得分:1)
你在案件中对C进行了限制,因为javascript具有案例意义,因此无法运行。
var x;
var a = 12;
var b = 20;
x= parseInt(prompt("Enter your Choice"));
switch(x)
{
case 1 : document.write("The Sum is : ",a+b);
break;
case 2 : document.write("The Difference is : ",a-b);
break;
case 3 : document.write("The Product is : ",a*b);
break;
case 4 : document.write("The quotient is : ",a/b);
break;
default : document.write("Invalid Choice");
break;
}
这应该有效。
答案 1 :(得分:0)
将Case
更改为case
,JavaScript是区分大小写的编程语言。
查看here了解更多信息.. !!
<html>
<body>
<script language = "javascript">
var x;
var a = 12;
var b = 20;
x= parseInt(prompt("Enter your Choice"));
switch(x)
{
case 1 : document.write("The Sum is : ",a+b);
break;
case 2 : document.write("The Difference is : ",a-b);
break;
case 3 : document.write("The Product is : ",a*b);
break;
case 4 : document.write("The quotient is : ",a/b);
break;
default : document.write("Invalid Choice");
break;
}
</script>
</body>
</html>
这是相同的工作条件代码。