switch implements a code example of a two number operation

  • 2020-06-01 11:08:12
  • OfStack

The specific code is as follows:


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

Related articles: