-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (24 loc) · 1.11 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
function compute()
{
var principal = document.getElementById("principal").value;
if (principal < 1) {
alert("Enter a positive number.");
document.getElementById("principal").focus();
return;
}
var rate = document.getElementById("rate").value;
var years = document.getElementById("years").value;
var interest = principal * years * rate / 100;
var year = new Date().getFullYear() + parseInt(years);
var result_text = `If you deposit <span style="background-color: yellow">${principal}</span>,<br>`;
result_text += `at an interest rate of <span style="background-color: yellow">${rate}%</span>.<br>`;
result_text += `You will receive an amount of <span style="background-color: yellow">${interest}</span>,<br>`;
result_text += `in the year <span style="background-color: yellow">${year}</span><br>`;
document.getElementById("result").innerHTML = result_text;
document.getElementById("principal").focus();
}
function updateRate()
{
var rateval = document.getElementById("rate").value;
document.getElementById("rate_val").innerText = rateval + '%';
}