-
Notifications
You must be signed in to change notification settings - Fork 336
/
simple interest calculator using HTML, CSS & Javascript
166 lines (158 loc) · 3.8 KB
/
simple interest calculator using HTML, CSS & Javascript
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<head>
<title>Simple Interest Calculator</title>
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=PT+Sans&display=swap" rel="stylesheet">
<!-- custom style css -->
<style>
body
{
background-color: #9C9EFE;
color: #ffffff;
font-family: 'PT Sans', sans-serif;
}
.container
{
background-color: #ffffff;
color: #000000;
width: 625px;
padding: 40px;
border-radius: 15px;
margin-top:2%;
margin-left: auto;
margin-right: auto;
box-shadow: rgba(0, 0, 0, 0.12) 0px 1px 3px, rgba(0, 0, 0, 0.24) 0px 1px 2px;
}
/* #result
{
display: none;
} */
.contents
{
margin-left: 80px;
}
table td
{
padding-bottom: 10px;
}
#compute
{
margin-top:20px;
margin-bottom: 20px;
background-color: #3CCF4E;
border-radius:8px;
border: 20px;
color: white;
font-size:20px;
height: 40px;
width: 300px;
box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 2px 6px 2px;
}
#principal{
height: 25px;
width: 190px;
}
#years{
height: 35px;
width: 200px;
}
.highlight
{
background-color: #ffff00;
}
span{
font-size:18px;
}
</style>
</head>
<body>
<div class="container">
<h1>Simple Interest Calculator</h1>
<div class="contents">
<table id="table">
<tbody>
<tr>
<td class="labels"><b>Amount</b></td>
<td>
<input type="number" id="principal">
</td>
</tr>
<tr>
<td class="labels"><b>Interest Rate</b></td>
<td>
<input type="range" min="1" max="20" step="0.25" value="10.25" id="rate" name="rate" onchange="SliderValue()">
<span id="rate_display">10.25%</span>
</td>
</tr>
<tr>
<td class="labels"><b>No. of Years</b></td>
<td>
<select name="years" id="years">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</td>
</tr>
</tbody>
</table>
<button id="compute" onclick="compute()">Calculate Interest</button> <br>
<span id="result"> </span>
<span id="result2"> </span>
</div>
</div>
<script>
function compute()
{
var principal = document.getElementById("principal").value;
if(principal !== "")
{
if (principal <= 0){
alert("Enter a positive number");
document.getElementById("principal").focus();
return;
}
}
else{
alert("Enter number Amount..");
return;
}
var rate = document.getElementById("rate").value;
var years = document.getElementById("years").value;
var interest = principal * years * rate / 100;
var dateNow = new Date();
var yearNow = parseInt(dateNow.getFullYear()) + parseInt(years);
var resultDisplay = document.getElementById("result");
resultDisplay.innerHTML = "<br/> ➔ If you deposit " + "<span class='highlight'>" + principal + "</span> Rupees.<br/>" + "<br>➔ At an interest Rate of "+ "<span class='highlight'>" + rate + "</span>%." + "<br/><br/>➔ You will receive an amount of " + "<span class='highlight'>" + interest + "</span> Rupees" + " in the year " + "<span class='highlight'>" + yearNow + "</span>";
var full_Display = document.getElementById("result2");
var t = parseFloat(principal) + parseFloat(interest);
full_Display.innerHTML = "<br/><br/> ➔ Your Total amount is: <span class='highlight'>" +t+ "</span> Rupees.";
}
function SliderValue()
{
var slider = document.getElementById("rate");
var output = document.getElementById("rate_display");
output.innerHTML = slider.value; // Display the default slider value
// Update the current slider value (each time you drag the slider handle)
slider.oninput = function()
{
output.innerHTML = this.value;
}
}
</script>
</body>
</html>