as11

by chris richarde

HTML

Enter value within range of Rain Table 
(0=>6)
<br><br>
0 hours => 0.00 ,
1 hours => 0.04 ,
2 hours => 0.11 ,
3 hours => 0.60 ,
4 hours => 0.87 ,
5 hours => 0.95 ,
6 hours => 1.00
<br>
<input type="text"  id="number"><br>

<br>
<input type="button" value="Enter" id="click" onClick='runNums()'>
<br>
<br>
<div id='output1'>

JavaScript

var rainTable = [0.00,0.04,0.11,0.60,0.87,0.95,1.00];

function runNums(){
	var input = document.getElementById("number").value;
 
 	if (input < 0 || input>6){
  document.getElementById('output1').innerHTML= "please enter number within range of rain table";
  }	
 
 
 while (input >= 0 && input<=6){
 
 	if(input== 0||input== 1||input==2||input==3||input==4||input==5||input==6){
    	document.getElementById('output1').innerHTML= rainTable[input]*100 + "  % after "+input+ "  hours";
    }
 	else {
  	
   	var input1 =Math.floor(input);
   	var input2 = Math.ceil(input);
   	var table1 = rainTable[input1];
    var table2 = rainTable[input2];
    var percentage = parseFloat(table1+(table2-table1)*((input-input1)/(input2-input1))).toFixed(2);
    
    document.getElementById('output1').innerHTML= percentage*100 + " % after "+input+" hours";
  		}
		break;
    }	
  
}