Assignment 11 Index/Lookup Table

Lookup Rainfall

by Daniel Eberhart

HTML

<!--This script will add the text box that is used, as well as create a button-->
<!--Programmed by Daniel Eberhart
COP 3530
Assignment 11
3/26/17
The purpose of this assignment is to create an array/list and be able to input a number and calculate the answer by interpolating between 2 numbers to find the exact solution
-->

<H2 id='Title'>COP 3530: Lookup Table, Assignment 11</H2>
<H4 id='programmed'> Programmed by: Daniel Eberhart </H4>
In the box given, Enter a value between 0 and 6. 
</br>
<input type="text" id="text" /input>
<button type="button" id="button" onclick = "Search()">Enter</button>
<div id="answer"></div>
<div id="test"></div>
Note: The input can contain decimal values, if desired. </br>
</br>
</br>
% for referencing data: </br>
 0: 0.00 % </br>
 1: 0.04% </br>
 2: 0.11%</br>
 3: 0.60%</br>
 4: 0.87%</br>
 5: 0.95%</br>
 6: 1.00%</br>

JavaScript

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

function Search(){ //Creates the function that associates with the text box
var output = ""; // Variable that associates with the output/answer
  var input = document.getElementById("text").value; //User input
  input.toString(); //Converts the user input into a string value
  var a = parseInt(input[0]);
  var b = a +1;
  a = list[a];
  var decimal = input[2]/10;
 var length = input.length;
 
 var b = list[b];
 
if (length == 1){
    output = list[input];
  }  else {
    var test = (a + (b-a) * decimal);
    
 
  output=Math.round(test*1000)/1000; 
  }
  
document.getElementById("answer").innerHTML = "this is the value " + output;  

}