-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
64 lines (61 loc) · 2.1 KB
/
index.html
File metadata and controls
64 lines (61 loc) · 2.1 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="main.css">
<body>
<div>
<form>
<label>Principle:</label>
<br>
<input type="number" step="0.01" id="principle"></input>
<br>
<label>Interest Rate(in percent):</label>
<br>
<input type="number" step="0.01" id ="interest-rate"></input>
<br>
<label>Number of Years:</label>
<br>
<input type="number" step="1" id="num-years"></input>
</form>
<label for="compounding-periods">How Investment is Compounded:</label>
<br>
<select name="compounding-periods" id="compounding-periods">
<option value="">--select--</option>
<option value="Yearly">Yearly</option>
<option value="Quarterly">Quarterly</option>
<option value="Monthly">Monthly</option>
<option value="Weekly">Weekly</option>
<option value="Daily">Daily</option>
</select>
</form>
<button id="calcButton" onclick="calculate()">Calculate!</button>
<p id="amount">Amount: $0.00</p>
</div>
<script>
function calculate() {
var amount = 0;
var principle = Number(document.getElementById("principle").value);
var interestRate = Number(document.getElementById("interest-rate").value / 100);
var years = Number(document.getElementById("num-years").value * 1);
var compoundingPeriods = document.getElementById("compounding-periods").value;
console.log(compoundingPeriods);
var multiplier = 1;
if (compoundingPeriods == "Yearly"){
multiplier = 1;
}
if (compoundingPeriods == "Daily"){
multiplier = 365;
}
// Round to nearest hundredth and add functionlity for other periods
finalAmount = principle * Math.pow(1+(interestRate/multiplier),(years/multiplier));
console.log((1+(interestRate/multiplier))**(compoundingPeriods/multiplier));
console.log(principle);
console.log(interestRate);
console.log(compoundingPeriods);
console.log(years);
console.log("Multuplier " + multiplier);
console.log(finalAmount);
document.getElementById("amount").innerHTML = "Amount: $" + finalAmount;
}
</script>
</body>
</html>