34 lines
847 B
HTML
34 lines
847 B
HTML
|
<html>
|
||
|
<head>
|
||
|
<title>Example 7.2</title>
|
||
|
<script>
|
||
|
function quotient(x,y)
|
||
|
{
|
||
|
illegal = "Illegal division operation";
|
||
|
if (y != 0)
|
||
|
return x/y;
|
||
|
else
|
||
|
return illegal;
|
||
|
}
|
||
|
function clickIt()
|
||
|
{
|
||
|
var divTop = parseFloat(prompt("Enter the divisor:"));
|
||
|
var divBottom = parseFloat(prompt("Enter the dividend:"));
|
||
|
document.getElementById('division').innerHTML = (divTop + " divided by " + divBottom);
|
||
|
var division;
|
||
|
division = quotient(divTop, divBottom);
|
||
|
if (isNaN(division))
|
||
|
division = "illegal division operation";
|
||
|
else
|
||
|
division = division.toFixed(2);
|
||
|
document.getElementById('result').innerHTML = division;
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<input type ="button" onclick="clickIt()" value = "Enter a division problem"></button>
|
||
|
<h2><span id = "division"> </span></h2>
|
||
|
<h2>The result is: <span id = "result"> </span></h2>
|
||
|
</body>
|
||
|
</html>
|