-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (23 loc) · 1.05 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
function compute(){
var principal = document.getElementById("principal").value;
var rate = document.getElementById("rate").value;
var years = document.getElementById("years").value;
var interest = money_round(principal * years * rate / 100);
var year = new Date().getFullYear()+parseInt(years);
if(isNaN(principal) || principal <= 0){
alert("Enter a positive number.")
principal.focus();
return;
}
//to round up to two decimal places
function money_round(num) {
return Math.ceil(num * 100) / 100;
}
var result = document.getElementById("result");
return result.innerText = "If you deposit $" + principal + ",\n at an interest rate of " + rate +"%.\n You will receive an amount of $" + interest + ",\n in the year of " + year;
}
//function to read the values of the range slider and display it in the <span> adjacent to the slider
function updateRate(){
var rateVal = document.getElementById("rate").value;
document.getElementById("rate_val").innerText=rateVal + "%";
}