Assignment 11: Interpolation
by MimiE
HTML
</h4>
<p id="demo"></p>
<h4>
<p id="title">Assingment 11: "Interpolation"</p>
<p id="myP">Enter a Number Between 0 and 6:</p>
<input type="textbox" id="input">
<input type="button" value="Calculate" onclick="interpolation();" /><br><br>
<div id="output"></div>
JavaScript
document.getElementById("title").style.height = "30px";
document.getElementById("title").style.color = "purple";
document.getElementById("title").style.fontFamily = "arial,Charcoal,sans-serif";
document.getElementById("title").style.fontWeight = "900";
document.getElementById("myP").style.color = "blue";
var array = [0.00, 0.04, 0.11, 0.60, 0.87, 0.95, 1.00];
function interpolation() {
var str = "";
var n = document.getElementById("input").value;
if (n < 0.00 || n > 6.0) {
str += "Please enter a number between 0 and 6 and press calculate.";
document.getElementById("output").innerHTML = str;
} else {
var calc1 = Math.floor(n);
var calc2 = Math.ceil(n);
var step1 = array[calc2] - array[calc1];
var step2 = n - calc1;
var step3 = step1 * step2;
var step4 = array[calc1] + step3;
str += "Total: " + step4.toPrecision(2);
document.getElementById("output").innerHTML = str;
}
}