SoFunction
Updated on 2025-04-11

Switch implements a two-digit operation code example

The specific code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Write a function with two variables and an operator,Received on callpromptenter</title>
<script language="javascript" type="text/javascript">
function account()
{
   var op1=prompt("Please enter the first number:","");
  var op2=prompt("Please enter the second number:","");
  var sign=prompt("Please enter the operator symbol","")
  var result;
  opp1=parseFloat(op1);
  opp2=parseFloat(op2);
  switch(sign)
  {
    case "+":
    result=opp1+opp2;
    alert("The result of the two numbers is:"+result);
    break;
    case "-":
    result=opp1-opp2;
    alert("The result of the two numbers is:"+result);
    break;
    case "*":
    result=opp1*opp2;
    alert("The result of the two numbers is:"+result);
    break;
    default:
    result=opp1/opp2;
    alert("The result of the two numbers is:"+result);
    break;
  }
}
</script>
</head>
<body>
<input name="btn" type="button" value="Calculate the result of two numbers" onclick="account();" />
</body>
</html>

The above is the code example of the two-digit calculation that the switch has introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!