-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (28 loc) · 1.18 KB
/
script.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
// calculate the simple interest A = P * r * t
function compute()
{
var principal = document.getElementById("principal").value;
// display error if amount is not valid
if (principal <= 0) {
alert("Please enter a positive Amount");
document.getElementById("principal").focus();
}
// calculate total interest and display result
else {
//calculate
var rate = document.getElementById("rate").value;
var years = parseInt(document.getElementById("years").value);
var amount = principal * years * rate / 100;
var currentYear = new Date().getFullYear();
years += currentYear;
//display result
result = document.getElementById("result").innerHTML= `If you deposit \<mark\>${principal}\</mark\>,
\<br\>at an interest rate of \<mark\>${rate}%\</mark\>.\<br\>You will receive an amount of \<mark\>
${amount}\</mark\>,\<br\>in the year \<mark\>${years}\</mark\>\<br>`;
}
}
// dynamically update the value of the interest rate with highlighted values
function updateRate() {
var rateval = document.getElementById("rate").value + "%";
document.getElementById("rate_val").innerText=rateval;
}