JSFiddle - React, Tailwind, and code Playground

by wooozy

HTML

<h1>Assignment 10</h1>

<label>Enter value here to get rainfall:</label><br><br>
<input type="text" id="theNum" /><button onclick="createValues()">Get Value</button><br><br>
<p id='firstOutput'></p>
<p id='secondOutput'></p>

JavaScript

function createValues(){

var hour = parseFloat(document.getElementById('theNum').value);
var x = [0,1,2,3,4,5,6];
var y = [0,0.04,0.11,0.60,0.87,0.95,1];
var hour_floor = Math.floor(hour);
var rainfall = 0;
debugger;
 if ((!(isNaN(hour))) && (hour<6) && (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('firstOutput').innerHTML = "The Rainfall is:" + rainfall.toString();
   document.getElementById('secondOutput').innerHTML = "";
 }
 else if (hour==6){
 rainfall = y[6];
 document.getElementById('firstOutput').innerHTML = "The Rainfall is:" + rainfall.toString();
 document.getElementById('secondOutput').innerHTML = "";
 }
 else
 {
 document.getElementById('secondOutput').innerHTML = "Enter a number between 0 and 6.";
  document.getElementById('firstOutput').innerHTML = "";
 }
 
}