作者:love_xiao奇 | 来源:互联网 | 2023-10-12 14:09
function computer(){
var num1=prompt(‘请输入第一个数:’);
var num2=prompt(‘请输入第二个数:’);
var operator=prompt(‘请输入运算符:’);
var result;
switch(operator){
case “+”:result=parseFloat(num1)+parseFloat(num2);
break;
case “-“:result=num1-num2;
break;
case “*”:result=num1*num2;
break;
case “/”:result=num1/num2;
break;
}
alert(“运算结果:”+num1+operator+num2+”=”+result);
}
computer();