js实现简单的四则运算
程序员文章站
2022-03-08 23:40:16
...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>四则运算</title>
<script type="text/javascript">
function account(){
var num1 = prompt("请输入第一个值:","");
// alert(typeof(num1));
var num11 = parseInt(num1);
var num2 = prompt("请输入第二个值:","");
var num22 = parseInt(num2);
var ysf = prompt("请输入运算符:","");
var result ;
switch(ysf){
case "+":
result = num11 + num22;
break;
case "-":
result = num11 - num22;
break;
case "*":
result = num11 * num22;
break;
case "/":
if(num22!=0){
result = num11 / num22;
}else{
alert("除数不能为0");
}
break;
}
document.write(result+"<br />");
}
</script>
</head>
<body>
<button οnclick="account()">点击计算两个数的值</button>
</body>
</html>