-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
127 lines (92 loc) · 3.24 KB
/
index.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
var cartList, totalPrice, menu;
// Describe this function...
function addToCart() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
let element_cartList = document.getElementById('cartList');
let new_li = document.createElement('li');
new_li.innerText = cartList.pop();
element_cartList.appendChild(new_li);
}
// Describe this function...
function total_price() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
let element_total = document.getElementById('total');
element_total.innerText = totalPrice.reduce((a,b) => a+b, 0);
}
cartList = [];
totalPrice = [];
document.getElementById('product1').addEventListener('click', (event) => {
cartList.push('Flying Disc Toy');
totalPrice.push(1.98);
addToCart();
total_price();
});
document.getElementById('product2').addEventListener('click', (event) => {
cartList.push('Chew Toy');
totalPrice.push(2.35);
addToCart();
total_price();
});
document.getElementById('product3').addEventListener('click', (event) => {
cartList.push('Dog Treat Puzzle For Fun Slow Feeder');
totalPrice.push(7.14);
addToCart();
total_price();
});
document.getElementById('product4').addEventListener('click', (event) => {
cartList.push('Cozy Hot Dog-Shaped Pet Bed');
totalPrice.push(28.1);
addToCart();
total_price();
});
document.getElementById('product5').addEventListener('click', (event) => {
cartList.push('Double Bowls Set');
totalPrice.push(10.15);
addToCart();
total_price();
});
document.getElementById('product6').addEventListener('click', (event) => {
cartList.push('Hair Remover Brush');
totalPrice.push(4.1);
addToCart();
total_price();
});
document.getElementById('product7').addEventListener('click', (event) => {
cartList.push('Quick-Dry Bath Towel');
totalPrice.push(6.2);
addToCart();
total_price();
});
document.getElementById('product8').addEventListener('click', (event) => {
cartList.push('Car Seat Comfortable And Waterproof');
totalPrice.push(22.5);
addToCart();
total_price();
});;
/* Build an image carousel */
var urlImages;
// Describe this function...
function firstImage() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
let element_image = document.getElementById('image');
element_image.setAttribute("src", urlImages[0]);
urlImages.push(urlImages.shift());
}
// Describe this function...
function nextImage() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
firstImage();
}
// Describe this function...
function previousImage() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
nextImage();
}
urlImages = ['https://img.kwcdn.com/product/1dab9add96/e4484c3a-7678-47f0-a867-3dee1afa1749_800x800.jpeg?imageView2/2/w/800/q/70/format/webp', 'https://img.kwcdn.com/product/Fancyalgo/VirtualModelMatting/ff98b17056d9227c6d48b562359062ea.jpg?imageView2/2/w/800/q/70/format/webp', 'https://img.kwcdn.com/product/fancy/e20b8972-5308-425a-ba33-ec5df0d33df0.jpg?imageView2/2/w/800/q/70/format/webp'];
firstImage();
document.getElementById('next').addEventListener('click', (event) => {
nextImage();
});
document.getElementById('previous').addEventListener('click', (event) => {
previousImage();
});