-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (124 loc) · 5.38 KB
/
script.js
File metadata and controls
132 lines (124 loc) · 5.38 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
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
const calculateButton = document.querySelector('.calculate');
const clearButton = document.querySelector('.clear');
const totalFeesInput = document.querySelector('#totalFees');
const scholarshipAmountInput = document.querySelector('#scholarshipAmount');
const categoryDiv = document.querySelector('#category')
const info = document.querySelector('#info');
const error = document.querySelector('#error');
const schorlarshipDisplay = document.querySelector('#scholarship');
const houseHoldDisplay = document.querySelector('#houseHold');
const totalLoanDisplay = document.querySelector('#totalLoan');
const feesLoanDisplay = document.querySelector('#feesLoan');
const upkeepDisplay = document.querySelector('#upkeep');
const schorlarshipDisplay_ = document.querySelector('#scholarship_');
const houseHoldDisplay_ = document.querySelector('#houseHold_');
const totalLoanDisplay_ = document.querySelector('#totalLoan_');
const feesLoanDisplay_ = document.querySelector('#feesLoan_');
const upkeepDisplay_ = document.querySelector('#upkeep_');
let totalLoan = 0;
let feesLoan = 0;
let houseHold = 0;
let bandCategory = 0;
let upkeepLoan = 0;
calculateButton.addEventListener('click', function() {
clear();
if ((totalFeesInput != null) && (scholarshipAmountInput != null )) {
let scholarshipAmountInput_ = scholarshipAmountInput.value;
let totalFeesInput_ = totalFeesInput.value;
if((isScholarshipNumber(scholarshipAmountInput_)) && (isFeesNumber(totalFeesInput_))){
let totalFees = parseFloat(totalFeesInput_);
const scholarship = parseFloat(scholarshipAmountInput_);
bandCategory = (scholarship * 100) / totalFees;
if ((bandCategory == 70) || (bandCategory == 60) || (bandCategory == 50) || (bandCategory == 40) || (bandCategory == 30)) {
switch (bandCategory) {
case 70:
upkeepLoan = 60000;
feesLoan = (totalFees * 25) / 100;
totalLoan = feesLoan + upkeepLoan;
houseHold = (totalFees * 5) / 100;
break;
case 60:
upkeepLoan = 55000;
feesLoan = (totalFees * 30) / 100;
totalLoan = feesLoan + upkeepLoan;
houseHold = (totalFees * 10) / 100;
break;
case 50:
upkeepLoan = 50000;
feesLoan = (totalFees * 30) / 100;
totalLoan = feesLoan + upkeepLoan;
houseHold = (totalFees * 20) / 100;
break;
case 40:
upkeepLoan = 45000;
feesLoan = (totalFees * 30) / 100;
totalLoan = feesLoan + upkeepLoan;
houseHold = (totalFees * 30) / 100;
break;
case 30:
upkeepLoan = 40000;
feesLoan = (totalFees * 30) / 100;
totalLoan = feesLoan + upkeepLoan;
houseHold = (totalFees * 40) / 100;
break;
default:
error.textContent = `Please check your values`;
break;
}
display(scholarship, houseHold, totalLoan, feesLoan, upkeepLoan, error);
}
else {
error.textContent = 'Please check your values';
return;
}
}
else {
error.textContent = 'Please check your values';
return;
}
}
else{
error.textContent = 'Enter valid values. Only numbers with no decimal points are allowed.';
}
});
clearButton.addEventListener('click', function() {
totalFeesInput.value = '';
scholarshipAmountInput.value = '';
clear();
});
function clear() {
error.textContent ='';
schorlarshipDisplay_.textContent = ``;
schorlarshipDisplay.textContent = ``;
houseHoldDisplay_.textContent = ``;
houseHoldDisplay.textContent = ``;
totalLoanDisplay_.textContent = ``;
totalLoanDisplay.textContent = ``;
feesLoanDisplay_.textContent = ``;
feesLoanDisplay.textContent = ``;
upkeepDisplay_.textContent = ``;
upkeepDisplay.textContent = ``;
info.textContent = "";
}
function display(scholarship, houseHold, totalLoan, feesLoan, upkeepLoan, error) {
error.textContent ='';
schorlarshipDisplay_.textContent = `Scholarship Amount:`;
schorlarshipDisplay.textContent = `${scholarship.toFixed(2)}`;
houseHoldDisplay_.textContent = `Household Amount:`;
houseHoldDisplay.textContent = `${houseHold.toFixed(2)}`;
totalLoanDisplay_.textContent = `Total Loan:`;
totalLoanDisplay.textContent = `${totalLoan.toFixed(2)}`;
feesLoanDisplay_.textContent = `Loan for fees:`;
feesLoanDisplay.textContent = `${feesLoan.toFixed(2)}`;
upkeepDisplay_.textContent = `Upkeep:`;
upkeepDisplay.textContent = `${upkeepLoan.toFixed(2)}`;
info.textContent = `This breakdown is for your whole academic year.
The upkeep will be divided into two. In your case, ${((upkeepLoan.toFixed(2)) / 2)} for each semester`;
}
// Checking if inputs are numbers
function isScholarshipNumber(scholarshipAmountInput_) {
return parseInt(scholarshipAmountInput_, 10).toString() === scholarshipAmountInput_;
}
function isFeesNumber(totalFeesInput_) {
return parseInt(totalFeesInput_, 10).toString() === totalFeesInput_;
}