-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
348 lines (301 loc) · 11.3 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
let year = document.getElementsByClassName("year")
for(let i =0; i <year.length; i++) {
const date = new Date();
year[i].textContent = date.getFullYear();
}
let total = 0.0;
let totalItems = 0
let delivery;
let finalTotal;
let basketItems = [];
let saladCount = 0;
let feastCount = 0;
let pokeCount = 0;
let roastCount = 0;
let medMixCount = 0;
let burgerCount = 0;
let curryCount = 0;
let lasagnaCount = 0;
let pizzaCount = 0;
let quicheCount = 0;
document.getElementById("total").textContent = total;
document.getElementById("totalItems").textContent = totalItems;
//Menu page
//Add items to cart
function addToCart(item){
if (item == 'salad'){
total += 14.99;
totalItems ++;
saladCount ++;
basketItems.push({name:'Superfood salad', price: 14.99});
document.getElementById("salad-box").textContent = saladCount;
}
else if(item == 'famfeast'){
total += 25.99;
totalItems++
feastCount ++;
basketItems.push({name: 'Family Feast', price: 25.99});
document.getElementById("feast-box").textContent = feastCount;
}
else if(item == 'poke'){
total += 12.99;
totalItems++;
pokeCount ++;
basketItems.push({name: 'Poke Bowl', price: 12.99});
document.getElementById("poke-box").textContent = pokeCount;
}
else if(item == 'roast'){
total += 28.99;
totalItems++;
roastCount++;
basketItems.push({name: 'Vegetable Roast', price: 28.99});
document.getElementById("roast-box").textContent = roastCount;
}
else if(item == 'medmix'){
total += 14.99;
totalItems++;
medMixCount ++;
basketItems.push({name: 'Meditteranean Mix Bowl', price: 14.99});
document.getElementById("medMix-box").textContent = medMixCount;
}
else if(item == 'burger'){
total += 16.99;
totalItems++;
burgerCount ++;
basketItems.push({name: 'Meat free burger', price: 16.99});
document.getElementById("burger-box").textContent = burgerCount;
}
else if(item == 'curry'){
total += 13.99;
totalItems++;
curryCount++;
basketItems.push({name: 'Veggie Curry', price: 13.99});
document.getElementById("curry-box").textContent = curryCount;
}
else if(item == 'lasagna'){
total += 15.99;
totalItems++;
lasagnaCount ++;
basketItems.push({name: 'Veggie Lasagna', price: 15.99});
document.getElementById("lasagna-box").textContent = lasagnaCount;
}
else if(item == 'pizza'){
total += 11.99;
totalItems++;
pizzaCount ++;
basketItems.push({name: 'Vegetable Pizza', price: 11.99});
document.getElementById("pizza-box").textContent = pizzaCount;
}
else{
total += 16.99
totalItems++;
quicheCount ++
basketItems.push({name:'Veggie stuffed quiche', price: 16.99});
document.getElementById("quiche-box").textContent = quicheCount;
}
flashOn();
document.getElementById("total").textContent = Math.trunc(total*100)/100;
localStorage.setItem("total", Math.trunc(total*100)/100);
document.getElementById("totalItems").textContent = totalItems;
}
//
//Remove items from cart
function remove(item){
if (item == 'salad'){
total -= 14.99;
totalItems --;
saladCount --;
document.getElementById("salad-box").textContent = saladCount;
let removeThis = basketItems.find(o => o.name === 'Superfood salad');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'famfeast'){
total -= 25.99;
totalItems--;
feastCount --;
document.getElementById("feast-box").textContent = feastCount;
let removeThis = basketItems.find(o => o.name === 'Family Feast');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'poke'){
total -= 12.99;
totalItems--;
pokeCount --;
document.getElementById("poke-box").textContent = pokeCount;
let removeThis = basketItems.find(o => o.name === 'Poke Bowl');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'roast'){
total -= 28.99;
totalItems--;
roastCount--;
document.getElementById("roast-box").textContent = roastCount;
let removeThis = basketItems.find(o => o.name === 'Vegetable Roast');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'medmix'){
total -= 14.99;
totalItems--;
medMixCount --;
document.getElementById("medMix-box").textContent = medMixCount;
let removeThis = basketItems.find(o => o.name === 'Meditteranean Mix Bowl');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'burger'){
total -= 16.99;
totalItems--;
burgerCount --;
document.getElementById("burger-box").textContent = burgerCount;
let removeThis = basketItems.find(o => o.name === 'Meat free burger');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'curry'){
total -= 13.99;
totalItems--;
curryCount--;
document.getElementById("curry-box").textContent = curryCount;
let removeThis = basketItems.find(o => o.name === 'Veggie Curry');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'lasagna'){
total -= 15.99;
totalItems--;
lasagnaCount --;
document.getElementById("lasagna-box").textContent = lasagnaCount;
let removeThis = basketItems.find(o => o.name === 'Veggie Lasagna');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else if(item == 'pizza'){
total -= 11.99;
totalItems--;
pizzaCount --;
document.getElementById("pizza-box").textContent = pizzaCount;
let removeThis = basketItems.find(o => o.name === 'Vegetable Pizza');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
else{
total -= 16.99
totalItems--;
quicheCount --;
document.getElementById("quiche-box").textContent = quicheCount;
let removeThis = basketItems.find(o => o.name === 'Veggie stuffed quiche');
let itemIndex = basketItems.indexOf(removeThis);
basketItems.splice(itemIndex, 1);
}
flashOn();
document.getElementById("total").textContent = Math.trunc(total*100)/100;
localStorage.setItem("total", Math.trunc(total*100)/100);
document.getElementById("totalItems").textContent = totalItems;
}
//
//Flash function
function flashOn(){
let changeColor = document.getElementById("basketBar").classList;
changeColor.add("flashOn");
setTimeout(flashOff,300);
}
function flashOff(){
let changeColor = document.getElementById("basketBar").classList;
changeColor.remove("flashOn");
}
//End of menu page
//Start of reviews page
function intervalStart(){
setInterval(reviews, 8000);
}
function reviews(){
const showReview = Math.floor(Math.random()*6)
console.log(showReview);
if(showReview == 1){
review1();
}
else if(showReview == 2){
review2();
}
else if(showReview == 3){
review3();
}
else if(showReview == 4){
review4();
}
else{
review5();
}
}
function review1(){
document.getElementById("reviewText").innerHTML = '<img src="./images/pizza.jpg" class="review-images" alt="pizza image" /><h2 class="green">Amazing food!</h2><h3>We ordered a veggie pizza and veggie burger meal, so tasty and great value!</h3><h2 class="green">~Jane</h2>';
}
function review2(){
document.getElementById("reviewText").innerHTML = '<img src="./images/vegcurry.jpg" class="review-images" alt="curry image" /><h2 class="green">Blown away!!!</h2><h3>First time trying a strictly vegetarian restaurant, was not disappointed!</h3><h2 class="green">~Charles</h2>';
}
function review3(){
document.getElementById("reviewText").innerHTML = '<img src="./images/vegburger.jpg" class="review-images" alt="poke bowl image" /><h2 class="green">So tasty</h2><h3>I\'m such a fan of CFG, they have the best veggie burgers in town</h3><h2 class="green">~Lily</h2>';
}
function review4(){
document.getElementById("reviewText").innerHTML = '<img src="./images/lasagna.jpg" class="review-images" alt="lasagna image" /><h2 class="green">No meat?!</h2><h3>I can\'t believe the lasagna has no meat in it, it was incredible!</h3><h2 class="green">~Josie</h2>';
}
function review5(){
document.getElementById("reviewText").innerHTML = '<img src="./images/quiche.jpg" class="review-images" alt="quiche image" /><h2 class="green">Everything is great</h2><h3>I think I\'ve tried everything from CFG and it has all been great, customer for life!</h3><h2 class="green">~Nick</h2>';
}
//End of reviews page
//Start of support page
function thanks(){
document.getElementById("contact-form").innerHTML = '<img class="customer-service" src="./images/customerservice.png" alt="customer service image"/><h2>Thank you for your message we will be in touch as soon as we can<br>If your enquiry is urgent please call us on <span class="green">01234 567 8910</span></h2>'
}
//End of support page
//Start of basket page
function goToBasket(){
localStorage.setItem("basketItems", JSON.stringify(basketItems));
}
function moveBasketAcross(){
let total = localStorage.getItem("total");
document.getElementById("subtotal").textContent = total;
if (total <50){
let cartTotal = Number(total);
let delivery = 3.99;
let calculateTotal = cartTotal+delivery;
finalTotal = Math.trunc(calculateTotal*100)/100;
document.getElementById("delivery").textContent = delivery;
document.getElementById("final-total").textContent = finalTotal;
listBasketItems();
listBasketPrices()
}
else{
let cartTotal = Number(total);
let delivery = 0;
let calculateTotal = cartTotal + delivery;
finalTotal = Math.trunc(calculateTotal*100)/100;
document.getElementById("delivery").textContent = delivery;
document.getElementById("final-total").textContent = finalTotal;
listBasketItems();
listBasketPrices()
document.getElementById("fruit-platter").textContent = "*Plus FREE fruit platter";
}
}
function listBasketItems(){
let basketContentItems = document.getElementById("basket-content");
cartItems = JSON.parse(localStorage.getItem("basketItems")) || [];
for (let i=0; i<cartItems.length; i++) {
const newElement = document.createElement("li");
newElement.textContent = cartItems[i].name;
basketContentItems.appendChild(newElement);
}
}
function listBasketPrices(){
let basketContentPrices = document.getElementById("basket-prices");
cartItems = JSON.parse(localStorage.getItem("basketItems")) || [];
for (let i=0; i<cartItems.length; i++) {
const newElement = document.createElement("li");
newElement.textContent = cartItems[i].price;
basketContentPrices.appendChild(newElement);
}
}