-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (63 loc) · 2.35 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
//Size Selector
$('.XL').on('click', function () {$(this).closest('.size').find('.sizeText').text('XL')});
$('.L').on('click', function () {$(this).closest('.size').find('.sizeText').text('L')});
$('.M').on('click', function () {$(this).closest('.size').find('.sizeText').text('M')});
$('.S').on('click', function () {$(this).closest('.size').find('.sizeText').text('S')});
//Color Selector
$('.blue-option').on('click', function() {$(this).closest('article').find('.t-shirt').attr('src', 'shirts/blue-front.png');
$(this).parent().next().css('background-color', '#80bbe5')});
//Pink Color
$('.pink-option').on('click', function() {$(this).closest('article').find('.t-shirt').attr('src', 'shirts/pink-front.png');
$(this).parent().next().css('background-color', '#e276a7')});
//Orange Color
$('.orange-option').on('click', function() {$(this).closest('article').find('.t-shirt').attr('src', 'shirts/yellow-front.png');
$(this).parent().next().css('background-color', '#e4b177')});
//Green Color
$('.green-option').on('click', function() {$(this).closest('article').find('.t-shirt').attr('src', 'shirts/green-front.png');
$(this).parent().next().css('background-color', '#8bb992')});
//Adding Items to Shopping Cart
$('.buy').on('click', function() {
let $ul = $('.cart');
let $li = `<li>${$(this).parent().next().text()}</li>`
$ul.append($li)});
//Updating price in Shopping Cart
$('.buy').on('click', function () {
let $shirtPrice = parseInt($(this).parent().next().find('.price').text());
let $cartPrice = parseInt($("#total").text());
let $test = $('#total');
$cartPrice += $shirtPrice;
$test.text($cartPrice);
cartLimit();
})
//Limit of 8 of each individual shirt
let saveShirt = 0;
let natureShirt = 0;
let forrestShirt = 0;
function cartLimit () {
let cartIcon = event.target;
let shirt = cartIcon.dataset.shirt;
if (shirt === "Save my Trees") {
saveShirt++;
if (saveShirt >= 8) {
sold1.style.display ='block';
}
} else if (shirt === "Nature Lover") {
natureShirt++;
if (natureShirt >= 8) {
sold2.style.display ='block';
}
} else {
forrestShirt++;
if (forrestShirt >= 8) {
sold3.style.display ='block';
}
}
}
//5% discount after five or more shirts
//work in progress
let shirtCounter = 0;
function cartDiscount (event) {
if (cartAdd() >= 5) {
console.log("discount");
}
}