-
Notifications
You must be signed in to change notification settings - Fork 0
/
dp.js
34 lines (27 loc) · 1.18 KB
/
dp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function compute()
{
let principal = document.getElementById("principal").value;
if(principal === "" || principal <= 0)
{
alert("Enter a positive number");
document.getElementById("principal").focus();
return;
}
let rate = document.getElementById("rate").value;
let years = document.getElementById("years").value;
let interest = principal * years * rate / 100;
let dateNow = new Date();
let yearNow = parseInt(dateNow.getFullYear().toString()) + parseInt(years);
let resultDisplay = document.getElementById("result");
resultDisplay.innerHTML = "If you deposit " + "<span class='highlight'>" + principal + "</span>." + ", <br> at an interest rate of "+ "<span class='highlight'>" + rate + "</span>%." + "<br> You will receive an amount of " + "<span class='highlight'>" + interest + "</span>" + ", <br> in the year " + "<span class='highlight'>" + yearNow + "</span>";
}
function SliderValue()
{
let slider = document.getElementById("rate");
let output = document.getElementById("rate_display");
output.innerHTML = slider.value;
slider.oninput = function()
{
output.innerHTML = this.value;
}
}