-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (41 loc) · 1.92 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
window.addEventListener("load", () => {
x = document.getElementById("years");
for(let i = 1; i <= 10; i++){y = document.createElement("option");y.value = i;y.text = i;x.add(y);}
console.log("Page loaded")
});
function compute()
{
var principal = parseInt(document.getElementById("principal").value);
var rate = document.getElementById("rate").value;
var years = parseInt(document.getElementById("years").value);
var debug = false;
if(principal < 1 || isNaN(principal) || principal === null){
alert("Enter a positive number");
document.getElementById("principal").focus();
document.getElementById("principal").style.borderColor = "red";
document.getElementById("principal").style.borderRadius = "3px";
document.getElementById("result").innerHTML="";
document.getElementById("principal").value=1;
}
else{
document.getElementById("principal").style.borderColor = "";
var interest = principal * years * rate /100;
var year = new Date().getFullYear()+parseInt(years);
var amount = principal+interest;
if(debug === true){
console.log(`principle: ${principal}`);
console.log(`rate: ${rate}`);
console.log(`years: ${years}`);
console.log(`interest: ${interest}`);
console.log(`year: ${year}`);
console.log(`amount: ${amount}`);
}
document.getElementById("result").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'> ${year} </span>\<br\>`
}
return false;
}
function updateRate()
{
var rateval = document.getElementById("rate").value;
document.getElementById("rate_val").innerHTML=rateval + "%";
}