Please answer in jsfiddle.net Answer must work on jsfiddle please do not attempt
ID: 3779660 • Letter: P
Question
Please answer in jsfiddle.net Answer must work on jsfiddle please do not attempt If you are not sure how to do it! Show it works please! Againnnn please make sure it runs!!! Assignment 11 Interpolation last edited by Dr. Ron Eaglin 2 weeks, 6 days ago Assignment 11 -Interpolation Objective Develop and implement a basic algorithm to perform a simple mathematical function using an array Supports learning objective 3 3. Implement data structures and algorithms in computer code. Introduction Just like many of the other data structures covered in this class indexes are also pretty straightforward. They are covered in Topic Indexing Techniques. For this module you will only have to complete a computer program. Assignment An interpolation table is a specific instance of a Lookup Table which is also a practical application of indexing, in this case numeric indexes. You will 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. 0.00 1 0.04 2 0.11 3 0.60 4 0.87 5 0.95 1.00 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. I must also be able to enter fractional numbers for example if l enter 4.5 it should return 0.91 by using interpolation (use standard linear interpolation -https llen.wikipedia.org bwikillnterpolation)Explanation / Answer
Direct jsfiddle link: https://jsfiddle.net/m148getL/
HTML:
Input value between 1-6 to get expected rainfall:
<br>
<input type="text" placeholder="0-6" id="idx" />
<button id="myBtn"> Calculate </button>
<hr>
<input type="text" placeholder="result" id="idRes" disabled/>
<br>
JAVASCRIPT:
//add onclick
document.getElementById("myBtn").addEventListener("click", calc);
function calc() {
//get inputs
var idx = document.getElementById("idx");
var res = document.getElementById("idRes");
var value = Math.abs(parseFloat(idx.value));
//get decimal & int individually
var decimal = value - Math.floor(value);
var floor = Math.floor(value);
//rain data
data = [0.00, 0.04, 0.11, 0.60, 0.87, 0.95, 1.00];
var result = 0;
if (decimal > 0)
res.value = decimal * data[floor + 1] + data[floor] * (1 - decimal); //applying interpolation
else
res.value = data[floor];
}