-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
25 lines (23 loc) · 1.22 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
// function that will compute the amount that the user will receive by aggregating the investment amount, investment period, and interest rate.
function compute()
{
var principal = document.getElementById("principal").value;
var rate = document.getElementById("rate").value;
var years = document.getElementById("years").value;
var interest = principal * years * rate / 100;
var amount = parseInt(principal) + parseFloat(interest);
var result = document.getElementById("result");
var year = new Date().getFullYear() + parseInt(years);
if (principal <= 0) {
alert('Please enter a positive number!');
document.getElementById("principal").focus();
}
else {
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>" + year + "</mark>" + "\<br\>";
}
}
// function that will update the interest rate slider when the user changes the slider value
function updateRate() {
var rateval = document.getElementById("rate").value;
document.getElementById("rate_val").innerText = rateval;
}