-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyScript.js
More file actions
221 lines (142 loc) · 5.59 KB
/
MyScript.js
File metadata and controls
221 lines (142 loc) · 5.59 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// <script type="text/javascript">
var val = 0;
var discount = 0;
var len ;
function Cal(){
debugger;
var price = document.getElementById("price").value;
var val = document.getElementById("count").value;
var matches= document.getElementById("discount").value;
var mat = matches.toUpperCase();
if (mat !== "DISC10" && mat !=="DISC25" && mat !== "DISC50") {
matches = check(mat).toString();
}
discount = matches.match(/(\d+)/)[0];
if (val==0) {
document.getElementById("answer").innerHTML = "Choose at least one item" ;
}
else{
if (discount ==0) {
var resule = price* val ;
document.getElementById("answer").innerHTML = "The total is"+ resule + "JD" +"no discount has been applied";
}
else{
if ((val *price) <= 100 ) {
var resule = (price*val) ;
document.getElementById("answer").innerHTML = "The total is "+ resule+ "JD , no discount has been applied ,to get the discount the amount should be greater than 100 JD" ;
}
else{
var resule = (price * val) - ((price * val)*(discount/100));
document.getElementById("answer").innerHTML = "The discount has been applied. The total is "+ resule + "JD" ;
}
}
}
}
function theme(){
debugger;
if (document.getElementById("body").style.background == "white") {
document.getElementById("body").style.background = 'black';
document.getElementById("footer").style.background = 'none';
document.getElementById("footer").style.color = "white"
document.getElementById("nav").style.border = "none";
for (let index = 0; index < len; index++) {
document.getElementsByClassName("desc")[index].style.color = "antiquewhite";
document.getElementsByClassName("desc")[index].style.border = "white solid 2px";
document.getElementsByClassName("desc")[index].style.background = "none";
}
}
else
{
document.getElementById("nav").style.border = "solid antiquewhite 5px";
document.getElementById("body").style.background = 'white';
document.getElementById("footer").style.background = 'antiquewhite';
document.getElementById("footer").style.color = "#333"
for (let index = 0; index < len; index++) {
document.getElementsByClassName("pop")[index].style.border = "solid #333 1px";
document.getElementsByClassName("desc")[index].style.color = "antiquewhite";
document.getElementsByClassName("desc")[index].style.border = "solid antiquewhite 5px";
document.getElementsByClassName("desc")[index].style.background = "#333";
}
}
}
window.onload = (function() {
// document.getElementById("body").style.background = 'black';
len = prompt("choose the number of image in the page (from 1 to 8)");
debugger
while (len <= 0 || len > 8 || isNaN(len) ){
len = prompt("choose the number of image in the page (from 1 to 8)");
}
debugger
for (var i = 0; i < len ; i++) {
document.getElementsByClassName("pop")[i].style.display = "block";
document.getElementsByClassName("desc")[i].style.display = "block";
}
alert("the while loop is in the calculation below, please scroll down")
});
function sleep(milliseconds) {
debugger;
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
function check(any){
debugger;
var mat = any;
while(mat !== "DISC10" && mat !=="DISC25" && mat !== "DISC50")
{
var matches2= prompt("enter the right code");
sleep(1000);
mat = matches2.toUpperCase();
// document.getElementById("answer").innerHTML = "Please enter a valid discount code" ;
}
return matches2;
}
// </script>
// $('.pop').dblclick(function(){
// debugger;
// $(this).remove();
// });
// function Theme() {
// }
// $('#theme').click(function(){
// debugger;
// if (document.getElementById("body").style.background == "white") {
// document.getElementById("body").style.background = 'black';
// }
// else
// {
// document.getElementById("body").style.background = 'white';
// $(".desc").css("color", "antiquewhite");
// $(".desc").css("border", "solid antiquewhite 5px");
// $(".desc").css("background-color", "#333");
// $("#title").css("-webkit-text-stroke", "1px black");
// }
// });
// function pop(){
// debugger;
// var bord = document.getElementsByClassName("pop")[0].style.border;
// if (bord == 'rgb(255, 255, 255)')
// {
// document.getElementsByClassName("pop")[0].style.border = "solid green 3px ";
// val += 1;
// }
// else{
// document.getElementsByClassName("pop")[0].style.border = "rgb(255, 255, 255)";
// val -= 1;
// }
// }
// function Cal2(){
// debugger;
// var price = document.getElementById("price").value;
// var count = document.getElementById("count").value;
// var discount = document.getElementById("discount").value;
// if ((count *price) <= 100) {
// document.getElementById("answer").innerHTML = "The amount should be greater than 100 JD" ;
// }
// else{
// var resule = (price*count) - ((price*count)*(discount/100))
// document.getElementById("answer").innerHTML = resule ;
// }
// }