计算器.html
<script type="text/javascript">
var num1=window.prompt('请输入第一个数');
var num2=window.prompt('请输入第二个数');
var operator=window.prompt('请输入运算符');
num1=parseFloat(num1);
num2=parseFloat(num2);
//调用函数
document.writeln(num1+operator+num2);
document.writeln("结果="+jiSuan(num1,num2,operator));
function jiSuan(num1,num2,operator)
{
var res=0;
if (operator=="+")
{
res=num1+num2
}else if (operator=="-")
{
res=num1-num2
}else if (operator=="*")
{
res=num1*num2
}else if (operator=="/")
{
res=num1/num2
}else if (operator=='%')
{
res=num1/num2
}
return res;
}
</script>