
Patrick B. answered 09/29/19
Math and computer tutor/teacher
<html>
<head>
<B><H1> Eggs Interactive </H1> </B>
</head>
<br>
<body>
</B>
# of eggs produced from chicken #1 <input type="text" id="input1" /> <br>
# of eggs produced from chicken #2 <input type="text" id="input2" /> <br>
# of eggs produced from chicken #3 <input type="text" id="input3" /> <br>
# of eggs produced from chicken #4 <input type="text" id="input4" /> <br>
# of eggs produced from chicken #5 <input type="text" id="input5" /> <br>
<button type = "button" onclick="go()"> CALCULATE </button>
<body/>
<script>
function go()
{
alert('Calculating ');
var numEggs = new Array(5);
numEggs[0] = document.getElementById("input1").value;
numEggs[1] = document.getElementById("input2").value;
numEggs[2] = document.getElementById("input3").value;
numEggs[3] = document.getElementById("input4").value;
numEggs[4] = document.getElementById("input5").value;
var total = 0;
for (var iLoop=0; iLoop<5; iLoop++)
{
alert(' # of eggs from chicken # ' +(iLoop+1) + ' = ' + numEggs[iLoop]);
total = total + Number(numEggs[iLoop]);
}
var dozen = Math.floor( total / 12);
var remainder = total % 12;
var outbuff = ' Total is ' + total.toString() +
' \n That is ' + dozen +
' dozen and ' + remainder + ' eggs left over ';
alert(outbuff);
}
</script>
</html>