-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
90 lines (79 loc) · 1.81 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
let isGrid = 0;
countv = 0;
countn = 0;
function AddData(id) {
let data = localStorage.getItem("data");
if (data == null) {
dataObj = [0, 0];
} else {
dataObj = JSON.parse(data);
}
countv = dataObj[0];
countn = dataObj[1];
if(id == 'veg-btn'){
countv+=1;
}
else if(id == 'non-btn'){
countn+=1;
}
SetToStorage(countv, countn);
show();
total();
}
function SetToStorage(countVeg, countNonveg) {
let data = localStorage.getItem("data");
if (data == null) {
dataObj = [0, 0];
} else {
dataObj = JSON.parse(data);
}
dataObj[0] = countVeg;
dataObj[1] = countNonveg;
localStorage.setItem("data", JSON.stringify(dataObj));
show();
total();
}
function show() {
let data = localStorage.getItem("data");
if (data == null) {
dataObj = [0, 0];
} else {
dataObj = JSON.parse(data);
}
let veg = document.getElementById('veg');
let nonveg = document.getElementById('non-veg');
veg.innerText = dataObj[0];
nonveg.innerText = dataObj[1];
total();
}
function total(){
let data = localStorage.getItem("data");
if (data == null) {
dataObj = [0, 0];
} else {
dataObj = JSON.parse(data);
}
let totalVeg = dataObj[0];
let totalNonVeg = dataObj[1];
let totalV = document.getElementById('total-veg');
let totalN = document.getElementById('total-nonveg');
let totalP = document.getElementById('total-price');
totalV.innerText = totalVeg;
totalN.innerText = totalNonVeg;
totalP.innerText = (totalVeg*50) + (totalNonVeg*70);
}
function resetData(){
let val = prompt('Type "Okay" to reset your data');
if(val == "Okay"){
localStorage.clear();
alert("You have successfully reseted your data.");
show();
total();
}
else{
alert("Hello welcome to my website");
alert("Your data is SAFE");
}
}
total();
show();