js实现简单的四则运算


<!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 onclick="account()">点击计算两个数的值</button>	
	</body>
</html>

 

posted @ 2020-03-25 13:33  JackieDYH  阅读(12)  评论(0编辑  收藏  举报  来源