assignment 11
fun with rainfall
by Kristy Bond
HTML
Hello! Rainfall has been recorded for the past 6 hours. Input an hour and get the data recorded. For example if the current time is 3:00 pm and you wish to know what the rain fall was at 2:30 you would input 5.5
<input type="textbox" id="timeIn" value="5.5" size="4" />
<input type="button" value="Inquire Rainfall" onClick="getPercentage();" />
<br/>
<p id='reportOut'></p>
JavaScript
//create a computer program that uses the following lookup table (interpolation table), allows a user to input a number and calculates the answer by interpolating between 2 numbers – or finds an exact solution.
//The table gives the amount of total rainfall (normalized to 1) that occurred during a rainfall event. For example at hour 3, 0.6 or 60% of the total rain had fallen. You will need to create a function that allows me to enter a number between 0 and 6, and it must return the total amount of rainfall that has occurred.
//fractions need to work too. (╯°□°)╯︵ ┻━┻)
var prntRainTable = '';
var prntCalc = '';;
var timeIn;
function getPercentage() {
timeIn = document.getElementById("timeIn").value;
prntCalc = 'Time Requested ' + timeIn + "<br/>";
for (var i = 0; i < rainTable.length; i++) {
nextKnownDataPoint = i + 1;
if (i == timeIn) {
prntCalc += 'for ' + timeIn + ': ' + rainTable[i] + "<br/>";
break;
}
if (i > timeIn && i < nextKnownDataPoint) {
prntCalc += ' > This falls between:' + rainTable[i - 1] + ' and ' + rainTable[i] + "<br/>";
rangeInBetween = rainTable[i] - rainTable[i - 1];
prntCalc += ' > Diffrence between the two inputs: ' + rangeInBetween + "<br/>";
scaleInBetween = 1 - (i - timeIn);
prntCalc += ' > Diffrence between the two indexes: ' + scaleInBetween + "<br/>";
extrapolatedValue = rainTable[i - 1] * 1 + (rangeInBetween * scaleInBetween);
extrapolatedValue = Math.ceil(extrapolatedValue * 1000) / 1000;
prntCalc += '>Rainfall at Requested Hour: ' + extrapolatedValue + "<br/>";
break;
}
}
generateReport();
}
function generateReport() {
prntRainTable = '';
for (var i = 0; i < rainTable.length; i++) {
prntRainTable += i + ' ' + rainTable[i] + "<br/>";
}
report = '';
report += "<br/>";
report += prntRainTable;
report += "<br/>";
report += prntCalc;
...