-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJS Task.html
99 lines (76 loc) · 3.15 KB
/
JS Task.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
95
96
97
98
99
<!DOCTYPE html>
<html>
<body>
<p>Click the "Calculate The Interest Button to Calculate The Interest For The Items Below"</p>
<ul>
<li>1. Principal = 2500, Time = 1.8 Years</li>
<li>2. Principal = 1000, Time = 5 Years</li>
<li>3. Principal = 3000, Time = 1 Year</li>
<li>4. Principal = 2000, Time = 3 Years</li>
</ul>
<button onclick="interestCalculator()">Calculate The Interest</button>
<script>
{
function interestCalculator()
{
var selectedNumber = prompt("Please Select an Item by item Number to Calculate interest");
var rateValue = 0;
var interestData;
var calculatedInterest;
var data = [
{principal : 2500, time : 1.8},
{principal : 1000, time : 5},
{principal : 3000, time : 1},
{principal : 2000, time : 3}
]
while ((selectedNumber < 1) || (selectedNumber > 4))
{
selectedNumber = prompt("Invalid Input Please Select an Item by item Number to Calculate interest");
}
if ((data[0].principal >= 2500) && (((data[0].time) > 1) && (data[0].time) < 3))
{
rateValue = 3;
}
else if ((data[0].principal >= 2500) && (data[0].time >= 3))
{
rateValue = 4;
}
else if ((data[0].principal < 2500) || (data[0].time <= 1))
{
rateValue = 2;
}
else
{
rateValue = 1;
}
if (selectedNumber == 1)
{
calculatedInterest = (data[0].principal * data[0].time * rateValue) / 100;
interestData = { principal : data[0].principal, time : data[0].time, rate : rateValue, interest : calculatedInterest }
alert("Your Interest is "+calculatedInterest+" Please Check Console Log for More Details")
}
else if(selectedNumber == 2 )
{
calculatedInterest = (data[1].principal * data[1].time * rateValue) / 100;
interestData = { principal : data[1].principal, time : data[1].time, rate : rateValue, interest : calculatedInterest }
alert("Your Interest is "+calculatedInterest+" Please Check Console Log for More Details");
}
else if(selectedNumber == 3)
{
calculatedInterest = (data[2].principal * data[2].time * rateValue) / 100;
interestData = { principal : data[2].principal, time : data[2].time, rate : rateValue, interest : calculatedInterest }
alert("Your Interest is "+calculatedInterest+" Please Check Console Log for More Details");
}
else
{
calculatedInterest = (data[3].principal * data[3].time * rateValue) / 100;
interestData = { principal : data[3].principal, time : data[3].time, rate : rateValue, interest : calculatedInterest }
alert("Your Interest is "+calculatedInterest+" Please Check Console Log for More Details");
}
console.log(interestData);
return interestData;
}
}
</script>
</body>
</html>