forked from Grace2102/192-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoring.js
123 lines (98 loc) · 3.83 KB
/
storing.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
customerobjs = [];
let iteminfo = [{item:"Black Beans", price: 2.00, quantity:1},
{item:"Pasta", price: 1.00, quantity:1},
{item:"Watties Spaghetti", price: 2.00, quantity: 1},
{item:"Canned Peaches", price: 2.50, quantity:1},
{item:"Chicken Soup", price: 2.80, quantity:1},
{item:"Corn Soup", price: 2.80, quantity:1},
{item:"Tomato Soup", price: 2.80, quantity:1},
{item:"Magnum Ice-Cream", price: 5.90, quantity:1},
{item:"Cadbury Chocolate", price: 3.50, quantity:1},
{item:"Kit-Kat", price: 3.50, quantity:1},
{item:"Heiniken Beer", price: 20.90, quantity:1},
{item:"Frozen Vege", price: 3.50, quantity:1},
{item:"Chicken nuggets", price: 10.80, quantity:1},
{item:"Shapes", price: 2.50, quantity:1},
{item:"Fries", price: 3.50, quantity:1},
{item:"Beverage beers", price: 8.90, quantity:1},
{item:"Milo", price: 4.90, quantity:1},
{item:"Sprite", price: 2.00, quantity:1},
{item:"Fanta", price: 2.00, quantity:1},
{item:"Coffee", price: 5.70, quantity:1},
{item:"Cola", price: 2.00, quantity:1},
{item:"Nescafe", price: 4.50, quantity:1},
{item:"Toothpaste", price: 3.00, quantity:1},
{item:"Shampoo", price: 6.90, quantity:1},
{item:"Body Lotion", price: 5.00, quantity:1},
{item: "Hand Sanitizer", price: 2.50, quantity:1},
{item:"Deodorant", price: 4.00, quantity:1},
{item:"Conditoner", price: 6.00, quantity:1},
{item:"Toothbrush", price: 2.00, quantity:1},
{item:"Perfume", price: 7.00, quantity:1}];
let itemsincart = [];
//accesses the customer details and stores it into an array
function newcustomerdetails(){
var objects = {};
let name = document.getElementById("name");
let address = document.getElementById("address");
let bankno = document.getElementById("bankcardno");
let email = document.getElementById("email");
objects.custname = name;
objects.custaddress = address;
objects.custbank = bankno;
objects.custemail = email;
customerobjs.push(objects);
}
//searching for products
const input = document.getElementById('searches');
const products = document.getElementsByClassName('product');
input.addEventListener('keyup', (e) => {search(e.target.value.toLowerCase())}
);
function search(item){
for (i = 0; i < products.length; i++) {
if (!products[i].innerText.toLowerCase().includes(item)) {
products[i].style.display = 'none';
} else {
products[i].style.display = 'stack-item';
console.log(products[i]);
}
}
}
function addToCart(item){
for (i=0; i<itemsincart.length; i++){
if(itemsincart[i].item == item){
itemsincart[i].item.quantity += 1;
}
else{
for (j=0;j<iteminfo.length;j++){
if (iteminfo[j].item == item){
itemsincart.push(iteminfo[i]);
}
}
}
}
totalsum();
}let total = document.getElementById("total");
//calculating total sum of products added to cart
function totalsum(){
let sum=0;
for (i=0; i<itemsincart.length; i++){
sum += itemsincart[i].price * itemsincart[i].quantity;
}
total.innerText="Total: $"+sum;
}
//storing feedback from users
function feedback(){
let email = docucment.getElementsByname("email");
let name = document.getElementsByName("name");
let feedback = document.getElementByName("feedback");
}
function displaycart(){
for (let i=0;i<myCart.length;i++){
for (let j=0; products.length;j++){
if (products[j].innerHTML.toLowerCase().contains(myCart[i].item)){
products[j].style.display = 'list-item';
}
}
}
}