JSFiddle - React, Tailwind, and code Playground

by Tori Hoelscher

HTML

<label>What is your rainfall for each hour living in Florida?</label><br><br>
<input type="text" id="rainfallHour" /><button onclick="GetRainfall()">Get Value</button><br><br>
<p id='output'></p>

JavaScript

function GetRainfall(){

var hour = parseFloat(document.getElementById('rainfallHour').value);
var x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24];
var y = [0,0.04,0.11,0.60,0.87,0.95,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5,6,7,7.5,8];
var hour_floor = Math.floor(hour);
var rainfall = 0;

 if ((!(isNaN(hour))) && (hour<24) && (hour>=0)){
  rainfall = ((x[hour_floor+1] - hour)*y[hour_floor] + (hour - x[hour_floor])*y[hour_floor+1]) / (x[hour_floor+1] - x[hour_floor]);  
  
  document.getElementById('output').innerHTML = "The Rainfall for this hour is:" + rainfall.toString();
 }
 else if (hour==24){
 rainfall = y[8];
 document.getElementById('output').innerHTML = "The Rainfall for this hour is:" + rainfall.toString();
 }
 else
 {
 alert ("Please enter a number 1-24");
	return num;
  document.getElementById('output').innerHTML = "";
  
 }}