-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
332 lines (302 loc) · 16.9 KB
/
main.js
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
//quiz arrays
let scoreOf5=[]
let scoreOf4=[]
let scoreOf3=[]
let scoreOf2=[]
let scoreOf1=[]
//Generates current year and adds it to footer
let year = document.getElementById("year")
const date = new Date();
year.textContent = date.getFullYear();
//Search function
function searchFunction(){
alert("I'm sorry but our search function is currently not working")
}
//Calculator function
function calculateExtra(calculatorForm){
const income = Number(calculatorForm.income.value);
if (isNaN(income) || income < 1) { alert("ERROR: Income must be a number greater than 0"); }
const rent = Number(calculatorForm.rent.value);
if (isNaN(rent)) { alert("ERROR: Rent must be a number"); }
const energy = Number(calculatorForm.energy.value);
if (isNaN(energy)) { alert("ERROR: Energy must be a number"); }
const water = Number(calculatorForm.water.value);
if (isNaN(water)) { alert("ERROR: Water must be a number"); }
const tax = Number(calculatorForm.tax.value);
if (isNaN(tax)) { alert("ERROR: Council tax must be a number"); }
const food = Number(calculatorForm.food.value);
if (isNaN(food)) { alert("ERROR: Food must be a number"); }
const phone = Number(calculatorForm.phone.value);
if (isNaN(phone)) { alert("ERROR: Phone/broadband must be a number"); }
const fuel = Number(calculatorForm.fuel.value);
if (isNaN(fuel)) { alert("ERROR: Fuel must be a number"); }
const insurance = Number(calculatorForm.insurance.value);
if (isNaN(insurance)) { alert("ERROR: Car insurance must be a number"); }
const tvLic = Number(calculatorForm.tvLic.value);
if (isNaN(tvLic)) { alert("ERROR: Tv License must be a number"); }
const tvSub = Number(calculatorForm.tvSub.value);
if (isNaN(tvSub)) { alert("ERROR: Tv subscription must be a number"); }
const other = Number(calculatorForm.other.value);
if (isNaN(other)) { alert("ERROR: Other must be a number"); }
const totalBills = rent+energy+water+tax+food+phone+fuel+insurance+tvLic+tvSub+other;
const extra = income-totalBills;
console.log(typeof(extra));
document.getElementById("extra").innerHTML = Math.floor(extra * 100)/100;
if(extra <=0){
document.getElementById("resultsInfo").innerHTML="<p class='fs-4 rounded border border-dark'>It's unfortunate that your financial situation is at this point, everyone deserves some fun money to treat themselves and their loved ones.Take a look at our <a class='text-success link-underline-success'href='benefits.html'>benefits</a> section to see if there are any benefits you may be entitled to. Also check out our <a class='text-success link-underline-success' href='money.html'>make money</a> section for ideas on how to boost your income. Please also reach out to some of the <a class='text-success link-underline-success' href='charities.html'>charities</a> to see if they can assist you.</p>";
}
else if(extra <=100){
document.getElementById("resultsInfo").innerHTML="<p class='fs-4 rounded border border-dark'>It's great that you can pay all of your bills and still have a little left over, even if it's not much. We would advise you to take a look at our <a class='text-success link-underline-success' href='benefits.html'>benefits</a> section to see if there are any benefits you may be entitled to. Also check out our <a class='text-success link-underline-success' href='money.html'>make money</a> section for ideas on how to boost your income.</p>"
}
else{
document.getElementById("resultsInfo").innerHTML=" <p class='fs-4 rounded border border-dark'>It's great that you can pay all of your bills. Check out our <a class='text-success link-underline-success' href='money.html'>make money</a> section for ideas on how to boost your income.</p>"
}
}
//Charities word flippers
function flipWording(name){
if(name == "housing"){
document.getElementById("housingCharity").innerHTML="<div class='p-5 border border-dark rounded'><a class='text-success link-underline-success' href='https://shelter.org.uk/' target='blank'><p class='fs-3 heart-title'>Shelter</p></a><p>Home is a human right. It's our foundation and it's where we thrive. Yet, every day millions of people are being devastated by the housing emergency. We exist to defend the right to a safe home. Because home is everything.</p></div>";
}
else if(name =="food"){
document.getElementById("foodCharity").innerHTML="<div class='p-5 border border-dark rounded'><a class='text-success link-underline-success' href='https://www.trusselltrust.org/' target='blank'><p class='fs-3 heart-title'>Trussel Trust</p></a><p>We support a nationwide network of food banks and together we provide emergency food and support to people facing hardship, and campaign for change to end the need for food banks in the UK.</p></div>";
}
else if(name =="energy"){
document.getElementById("energyCharity").innerHTML="<div class='p-5 border border-dark rounded'><a class='text-success link-underline-success' href='https://www.nea.org.uk/' target='blank'><p class='fs-3 heart-title'>National Energy Action</p></a><p>We are National Energy Action (NEA) - the national fuel poverty charity, working to ensure that everyone in England, Wales and Northern Ireland is warm and safe at home.</p></div>";
}
else if(name =="debt"){
document.getElementById("debtCharity").innerHTML="<div class='p-5 border border-dark rounded'><a class='text-success link-underline-success' href='https://www.debtadvicefoundation.org/' target='blank'><p class='fs-3 heart-title'>Debt Advice Foundation</p></a><p>Debt Advice Foundation is a registered national debt advice and education charity offering free, confidential support and advice to anyone worried about loans, credit and debt.</p></div>";
}
else{
document.getElementById("generalCharity").innerHTML="<div class='p-5 border border-dark rounded'><a class='text-success link-underline-success' href='https://www.citizensadvice.org.uk/' target='blank'><p class='fs-3 heart-title'>Citizens Advice</p></a><p>We give people the knowledge and confidence they need to find their way forward - whoever they are, and whatever their problem. Our national charity and network of local charities offer confidential advice online, over the phone, and in person, for free.</p></div>";
}
}
function flipWordingBack(name){
if(name =="housing"){
document.getElementById("housingCharity").innerHTML="<p class='display-4 p-5 border border-dark rounded'>Housing</p>"
}
else if(name =="food"){
document.getElementById("foodCharity").innerHTML="<p class='display-4 p-5 border border-dark rounded'>Food</p>";
}
else if(name =="energy"){
document.getElementById("energyCharity").innerHTML="<p class='display-4 p-5 border border-dark rounded'>Energy</p>";
}
else if(name =="debt"){
document.getElementById("debtCharity").innerHTML="<p class='display-4 p-5 border border-dark rounded'>Debt</p>";
}
else{
document.getElementById("generalCharity").innerHTML="<p class='display-4 p-5 border border-dark rounded'>General</p>";
}
}
//event listeners for charities
document.getElementById("housingCharity").addEventListener("mouseover", function(){ flipWording('housing'); });
document.getElementById("housingCharity").addEventListener("mouseout", function(){ flipWordingBack('housing'); });
document.getElementById("foodCharity").addEventListener("mouseover", function(){ flipWording('food'); });
document.getElementById("foodCharity").addEventListener("mouseout", function(){ flipWordingBack('food'); });
document.getElementById("energyCharity").addEventListener("mouseover", function(){ flipWording('energy'); });
document.getElementById("energyCharity").addEventListener("mouseout", function(){ flipWordingBack('energy'); });
document.getElementById("debtCharity").addEventListener("mouseover", function(){ flipWording('debt'); });
document.getElementById("debtCharity").addEventListener("mouseout", function(){ flipWordingBack('debt'); });
document.getElementById("generalCharity").addEventListener("mouseover", function(){ flipWording('other'); });
document.getElementById("generalCharity").addEventListener("mouseout", function(){ flipWordingBack('other'); });
//quiz functions
function answerQuestion(question,answer,now,next){
if(answer =='stronglyAgree'){
scoreOf5.push(question);
}
else if(answer == 'agree'){
scoreOf4.push(question);
}
else if(answer == 'neutral'){
scoreOf3.push(question);
}
else if(answer == 'disagree'){
scoreOf2.push(question);
}
else{
scoreOf1.push(question);
}
document.getElementById(now).style.display = 'none';
document.getElementById(next).style.display = 'inline';
}
function quizResults(){
if(scoreOf5.length >=1){
counter =0;
while (counter <scoreOf5.length){
if(scoreOf5[counter] == 'handsOn'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult1').style.display='block';
counter++;
}
else if(scoreOf5[counter] == 'observe'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult2').style.display='block';
counter++;
}
else if(scoreOf5[counter] == 'creative'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult3').style.display='block';
counter++;
}
else if(scoreOf5[counter] == 'teach'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult4').style.display='block';
counter++;
}
else if(scoreOf5[counter] == 'manage'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult5').style.display='block';
counter++;
}
else{
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult6').style.display='block';
counter++;
}
}
document.getElementById("retake").style.display='inline';
}
else if(scoreOf4.length >=1){
counter =0;
while (counter <scoreOf4.length){
if(scoreOf5[counter] == 'handsOn'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult1').style.display='block';
counter++;
}
else if(scoreOf4[counter] == 'observe'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult2').style.display='block';
counter++;
}
else if(scoreOf4[counter] == 'creative'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult3').style.display='block';
counter++;
}
else if(scoreOf4[counter] == 'teach'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult4').style.display='block';
counter++;
}
else if(scoreOf4[counter] == 'manage'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult5').style.display='block';
counter++;
}
else{
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult6').style.display='block';
counter++;
}
}
document.getElementById("retake").style.display='inline';
}
else if(scoreOf3.length >=1){
counter =0;
while (counter <scoreOf3.length){
if(scoreOf5[counter] == 'handsOn'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult1').style.display='block';
counter++;
}
else if(scoreOf3[counter] == 'observe'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult2').style.display='block';
counter++;
}
else if(scoreOf3[counter] == 'creative'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult3').style.display='block';
counter++;
}
else if(scoreOf3[counter] == 'teach'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult4').style.display='block';
counter++;
}
else if(scoreOf3[counter] == 'manage'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult5').style.display='block';
counter++;
}
else{
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult6').style.display='block';
counter++;
}
}
document.getElementById("retake").style.display='inline';
}
else if(scoreOf2.length >=1){
counter =0;
while (counter <scoreOf2.length){
if(scoreOf5[counter] == 'handsOn'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult1').style.display='block';
counter++;
}
else if(scoreOf2[counter] == 'observe'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult2').style.display='block';
counter++;
}
else if(scoreOf2[counter] == 'creative'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult3').style.display='block';
counter++;
}
else if(scoreOf2[counter] == 'teach'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult4').style.display='block';
counter++;
}
else if(scoreOf2[counter] == 'manage'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult5').style.display='block';
counter++;
}
else{
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult6').style.display='block';
counter++;
}
}
document.getElementById("retake").style.display='inline';
}
else{
counter =0;
while (counter <scoreOf1.length){
if(scoreOf5[counter] == 'handsOn'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult1').style.display='block';
counter++;
}
else if(scoreOf1[counter] == 'observe'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult2').style.display='block';
counter++;
}
else if(scoreOf1[counter] == 'creative'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult3').style.display='block';
counter++;
}
else if(scoreOf1[counter] == 'teach'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult4').style.display='block';
counter++;
}
else if(scoreOf1[counter] == 'manage'){
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult5').style.display='block';
counter++;
}
else{
document.getElementById('seeResult').style.display='none';
document.getElementById('quizResult6').style.display='block';
counter++;
}
}
document.getElementById("retake").style.display='inline';
}
}