forked from GKroon-Web/Investment-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (80 loc) · 2.64 KB
/
index.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive Investment Calculator</title>
<style>
body {
font-family: sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f0f0f0;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 5px;
}
input[type="number"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 15px;
}
button {
background-color: #007bff;
color: #fff;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Investment Calculator</h1>
<label for="investmentAmount">Investment Amount:</label>
<input type="number" id="investmentAmount" placeholder="Enter amount">
<label for="interestRate">Annual Interest Rate (%):</label>
<input type="number" id="interestRate" placeholder="Enter rate">
<label for="investmentYears">Investment Years:</label>
<input type="number" id="investmentYears" placeholder="Enter years">
<button id="calculateButton">Calculate</button>
<div id="result"></div>
</div>
<script>
const investmentAmountInput = document.getElementById('investmentAmount');
const interestRateInput = document.getElementById('interestRate');
const investmentYearsInput = document.getElementById('investmentYears');
const calculateButton = document.getElementById('calculateButton');
const resultDiv = document.getElementById('result');
calculateButton.addEventListener('click', () => {
const investmentAmount = parseFloat(investmentAmountInput.value);
const interestRate = parseFloat(interestRateInput.value) / 100; // Convert percentage to decimal
const investmentYears = parseFloat(investmentYearsInput.value);
if (isNaN(investmentAmount) || isNaN(interestRate) || isNaN(investmentYears)) {
resultDiv.textContent = "Please enter valid numbers for all fields.";
return;
}
const futureValue = investmentAmount * Math.pow(1 + interestRate, investmentYears);
resultDiv.textContent = `Your estimated future value: $${futureValue.toFixed(2)}`;
});
</script>
</body>
</html>