Lab15
This commit is contained in:
34
Chapter ZIPs/JavaScript/ch7/ex_7_2.html
Executable file
34
Chapter ZIPs/JavaScript/ch7/ex_7_2.html
Executable file
@@ -0,0 +1,34 @@
|
||||
<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>
|
Reference in New Issue
Block a user