RB_JSFiddle_A11
by Ryan Brown
HTML
<form id ="formski">
<p>
Below we are depciting total rainfall normalized to 1.
<br/><br/>
Please enter a value below to view the specific total rain percentage for that given time.
<br/>
<input type = "text" id = "userInput" value = "4.5"/>
<br/>
<button type ="button" id = "formbtn" onclick = "userTableResults()">
Find!
</button>
(Ex: 3.5 Represents the 3 hours and 30 minute mark.)
</p>
<p id = "totRainfall">
</p>
</form>
CSS
#formski, #formbtn
{
font-family: courier;
}
JavaScript
var array = [0.00, 0.04, 0.11, 0.60, 0.87, 0.96, 1.00];
function userTableResults()
{
var returnValue = "";
var uInput = document.getElementById("userInput").value;
uInput.toString();
var x = parseInt(uInput[0])
var y = x +1;
x = array[x];
var decimalValue = uInput[2]/10;
var length = uInput.length;
var y = array [y];
if (length == 1)
{
returnValue = array[uInput];
}
else
{
var calc = (x + (y-x) * decimalValue);
returnValue = Math.round(calc * 1000)/1000;
}
var percentage = returnValue * 100
document.getElementById("totRainfall").innerHTML = "Total rainfall at the: " + uInput + " timestamp was: " + returnValue + " or " + percentage + "%";
}