-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
121 lines (108 loc) · 3.65 KB
/
script.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
let totalPriceSpan = document.getElementById("totalPrice");
let numberMeet = 0;
let numberEgg = 0;
let numberOnion = 0;
let numberLettuce= 0;
const meetPrice = 5;
const eggPrice = 2;
function addMeet() {
if(numberMeet < 3){
numberMeet += 1;
let meetDiv = document.getElementById("meetImages");
let meetImg = document.createElement("img");
meetImg.src = "./images/meet-removebg-preview.png";
meetImg.alt = "meet";
meetDiv.appendChild(meetImg);
let currentTotalPrice = Number(totalPriceSpan.textContent);
totalPriceSpan.innerHTML = (currentTotalPrice + meetPrice);
}
}
function removeMeet() {
if(numberMeet > 0){
numberMeet -= 1;
let meetDiv = document.getElementById("meetImages");
if (meetDiv.childElementCount > 0) {
meetDiv.removeChild(meetDiv.lastElementChild);
let currentTotalPrice = Number(totalPriceSpan.textContent);
totalPriceSpan.innerHTML = (currentTotalPrice - meetPrice);
}
}
}
function addLettuce() {
if(numberLettuce < 5){
numberLettuce += 1;
let lettuceDiv = document.getElementById("lettuceImages");
let lettuceImg = document.createElement("img");
lettuceImg.src = "./images/lettuce-removebg-preview.png";
lettuceImg.alt = "lettuce";
lettuceDiv.appendChild(lettuceImg);
}
}
function removeLettuce() {
if(numberLettuce > 0){
numberLettuce -= 1;
let lettuceDiv = document.getElementById("lettuceImages");
if (lettuceDiv.childElementCount > 0) {
lettuceDiv.removeChild(lettuceDiv.lastElementChild);
}
}
}
function addEgg() {
if(numberEgg < 2){
numberEgg +=1;
let eggDiv = document.getElementById("eggImages");
let eggImg =document.createElement("img");
eggImg.src = "./images/egg-removebg-preview.png";
eggImg.alt="egg";
eggDiv.appendChild(eggImg);
let currentTotalPrice = Number(totalPriceSpan.textContent);
totalPriceSpan.innerHTML = (currentTotalPrice + eggPrice);
}
}
function removeEgg() {
if(numberEgg > 0){
numberEgg -= 1;
document.getElementById("eggImages").removeChild(document.getElementById("eggImages").lastElementChild);
totalPriceSpan.innerHTML = Number(totalPriceSpan.textContent - eggPrice);
}
}
function addOnion() {
if(numberOnion < 1){
numberOnion +=1;
let onionImg =document.createElement("img");
onionImg.src = "./images/onion-removebg-preview.png";
onionImg.alt="onion";
document.getElementById("onionImages").appendChild(onionImg);
}
}
function removeOnion() {
if(numberOnion > 0){
numberOnion -= 1;
document.getElementById("onionImages").removeChild(document.getElementById("onionImages").lastElementChild);
}
}
function PaymentDetails(){
if(numberMeet > 0){
document.getElementById("PaymentDetailsId").innerHTML = "Meet : " + " " + numberMeet ;
if(numberLettuce > 0){
document.getElementById("lettuceId").innerHTML = "Lettuce : " + " " + numberLettuce;
}else{
document.getElementById("lettuceId").innerHTML = "";
}
if(numberEgg > 0){
document.getElementById("eggId").innerHTML = "Egg : " + " " + numberEgg;
}else{
document.getElementById("eggId").innerHTML = "";
}
if(numberOnion > 0){
document.getElementById("onionId").innerHTML = "Onion : " + " " + numberOnion;
}else{
document.getElementById("onionId").innerHTML = "";
}
}else{
document.getElementById("PaymentDetailsId").innerHTML ="Must choose a main ingredient";
document.getElementById("lettuceId").innerHTML ="";
document.getElementById("eggId").innerHTML ="";
document.getElementById("onionId").innerHTML="";
}
}