-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaurav_1dArray.html
482 lines (449 loc) · 11.5 KB
/
saurav_1dArray.html
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<script>
var id = [];
var nam = [];
var number = [];
var email = [];
var password = [];
var birthDate = [];
var price = [];
var quantity = [];
var sumTotal = [];
var total = [];
var GST = 0;
var n = parseInt(prompt(" Enter the size of data ?"));
var startingId = parseInt(prompt("From where do you want to start the id ?"));
var flag = 0;
var attempts = 6;
var nameReg = /^[a-zA-Z]*$/;
var numberReg = /^\d{10}$/g;
var emailReg = /\S+@\S+\.\S+/g;
var birthDateReg =
/^((0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2})\S*$/;
var passwordReg = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{9,12}$/;
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const emailChar = "abcdefghijklmnopqrstuvwxyz";
const passwords =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@%+-'!*#$?^;:(){}[]/";
var doWhile = 0;
do {
var choice = parseInt(
prompt(
"What do want to do in your records ? \n1. Insert \n2. View \n3. Search \n4. Update \n5. Delete \n6. Exit"
)
);
if (choice == 1) {
//--------------------------INSERTION--------------------------------------
for (var i = 0; i < n; i++) {
// ID insert---
id.push(startingId++);
// Name insert---
attempts = 6;
flag = 0;
do {
var na = prompt("Enter the Name: (Atleast 3 characters)");
if (na.length < 3 || !nameReg.test(na)) {
alert("Invalid Name !!!");
attempts--;
if (attempts == 2) {
alert("You are left with 2 more attempts... \nMake it count !!!");
}
} else {
flag = 1;
}
} while (attempts != 0 && flag == 0);
// Random Name generate---
var len = 3 - na.length;
const charactersLength = characters.length;
for (var i = 0; i < len; i++) {
na += characters.charAt(Math.floor(Math.random() * charactersLength));
}
nam.push(na);
// Number insert---
attempts = 6;
flag = 0;
do {
var num = parseInt(
prompt("Enter the Number: (Number should be of 10 digits)")
);
if (!numberReg.test(num)) {
alert("Invalid Mobile Number !!!");
attempts--;
if (attempts == 2) {
alert("You are left with 2 more attempts... \nMake it count !!!");
}
} else {
flag = 1;
}
} while (attempts != 0 && flag == 0);
// Random Number generate---
// var result = "";
// var len = 10 - num.toString().length;
// for (var i = 0; i < len; i++) {
// result += (Math.floor(Math.random() * 10) + 1).toString();
// }
// number.push(num.toString() + result);
number.push(num);
// Email insert---
attempts = 6;
flag = 0;
do {
var em = prompt("Enter the email: ");
if (!emailReg.test(em)) {
alert("Invalid Email'Id !!!");
attempts--;
if (attempts == 2) {
alert("You are left with 2 more attempts... \nMake it count !!!");
}
} else {
flag = 1;
}
} while (attempts != 0 && flag == 0);
email.push(em);
// Password insert---
attempts = 6;
flag = 0;
do {
var pass = prompt(
"Enter the password: \n(Password must contain \natleast 1 alphabet, \natleast 1 number and \natleast1 special character & \nlength should be in range of 8 to 12 chars)"
);
if (!passwordReg.test(pass)) {
alert("Invalid Password !!!");
attempts--;
if (attempts == 2) {
alert("You are left with 2 more attempts... \nMake it count !!!");
}
} else {
flag = 1;
}
} while (attempts != 0 && flag == 0);
// Random Password generate---
// var len = 3 - pass.length;
// var result = "";
// for (var i = 0, n = passwords.length; i < len; ++i) {
// result += passwords.charAt(Math.floor(Math.random() * n));
// }
// password.push(pass + result);
password.push(pass);
// Birth Date insert---
attempts = 6;
flag = 0;
do {
var dob = prompt("Enter the birthdate: ");
if (!birthDateReg.test(dob)) {
alert("Invalid Birth Date !!!");
attempts--;
if (attempts == 2) {
alert("You are left with 2 more attempts... \nMake it count !!!");
}
} else {
flag = 1;
}
} while (attempts != 0 && flag == 0);
birthDate.push(dob);
// Price insert---
price.push(prompt("Enter the price: "));
// Quantity insert---
quantity.push(prompt("Enter the quantity: "));
sumTotal.push(price[i] * quantity[i]);
// GST insert---
GST = prompt("Enter GST rate: ");
total.push(sumTotal[i] + parseInt((sumTotal[i] * GST) / 100));
}
} else if (choice == 2) {
//----------------------------VIEW-------------------------------------
for (var i = 0; i < n; i++) {
alert(
"ID= " +
id[i] +
"\nName= " +
nam[i] +
"\nNumber= " +
number[i] +
"\nEmail= " +
email[i] +
"\nBirth Date= " +
birthDate[i] +
"\nPrice= " +
price[i] +
"\nQuantity= " +
quantity[i] +
"\nSum Total= " +
sumTotal[i] +
"\nTotal= " +
total[i]
);
}
} else if (choice == 3) {
//-----------------------SEARCHING--------------------------------
var ch = -1;
do {
var search = parseInt(
prompt(
"How do you want to SEARCH in the Records ? \n1.Through NAME \n2.Through NUMBER \n3.Through PRICE range \nEnter the choice. "
)
);
if (search == 1) {
var mk = -1;
do {
var searchName = prompt("Enter the Name you want to Search: ");
for (var i = 0; i < n; i++) {
if (searchName == nam[i]) {
mk = i;
alert(
"ID= " +
id[mk] +
"\nName= " +
nam[mk] +
"\nNumber= " +
number[mk] +
"\nEmail= " +
email[mk] +
"\nBirth Date= " +
birthDate[mk] +
"\nPrice= " +
price[mk] +
"\nQuantity= " +
quantity[mk] +
"\nSum Total= " +
sumTotal[mk] +
"\nTotal= " +
total[mk]
);
}
}
if (mk == -1) {
alert("Sorry!, This name is not in out records...");
var conti = parseInt(
prompt(
"Do still want to continue with \n1. another name \n2. Exit"
)
);
if (conti == 2) {
mk = 0;
}
}
} while (mk == -1);
} else if (search == 2) {
var mk = -1;
do {
var searchNum = prompt("Enter the Number you want to Search: ");
for (var i = 0; i < n; i++) {
if (searchNum == number[i]) {
mk = i;
alert(
"ID=" +
id[mk] +
"\nName=" +
nam[mk] +
"\nNumber=" +
number[mk] +
"\nEmail=" +
email[mk] +
"\nBirth Date=" +
birthDate[mk] +
"\nPrice=" +
price[mk] +
"\nQuantity=" +
quantity[mk] +
"\nSum Total=" +
sumTotal[mk] +
"\nTotal=" +
total[mk]
);
}
if (mk == -1) {
alert("Sorry!, This number is not in out records...");
var conti = parseInt(
prompt(
"Do still want to continue with \n1. another number \n2. Exit"
)
);
if (conti == 2) {
mk = 0;
}
}
}
} while (mk == -1);
} else if (search == 3) {
var mk = -1;
do {
var upperPriceRange = prompt(
"Enter the Upper Price Range you want to Search: "
);
var lowerPriceRange = prompt(
"Enter the Lower Price Range you want to Search: "
);
for (var i = id; i < id + n; i++) {
if (lowerPriceRange <= price[i] && upperPriceRange >= price[i]) {
mk = i;
alert(
"ID=" +
id[mk] +
"\nName=" +
nam[mk] +
"\nNumber=" +
number[mk] +
"\nEmail=" +
email[mk] +
"\nBirth Date=" +
birthDate[mk] +
"\nPrice=" +
price[mk] +
"\nQuantity=" +
quantity[mk] +
"\nSum Total=" +
sumTotal[mk] +
"\nTotal=" +
total[mk]
);
}
}
if (mk == -1) {
alert("Sorry!, This price range is not in out records...");
var conti = parseInt(
prompt(
"Do still want to continue with \n1. another price range \n2. Exit"
)
);
if (conti == 2) {
mk = 0;
}
}
} while (mk == -1);
} else {
alert("Please select appropriate Search choice. Thank You!");
}
var ch = parseInt(
prompt("Do still want to continue with \n1. Search \n2. Exit")
);
if (ch == 2) {
ch = 0;
}
} while (ch == -1);
} else if (choice == 4) {
//----------------------------UPDATE-----------------------------------
var mk = -1;
do {
var updateID = parseInt(prompt("Enter the ID for updation: "));
for (var i = 0; i < n; i++) {
if (updateID == id[i]) {
mk = i;
alert(
"ID=" +
id[mk] +
"\nName=" +
nam[mk] +
"\nNumber=" +
number[mk] +
"\nEmail=" +
email[mk] +
"\nBirth Date=" +
birthDate[mk] +
"\nPrice=" +
price[mk] +
"\nQuantity=" +
quantity[mk] +
"\nSum Total=" +
sumTotal[mk] +
"\nTotal=" +
total[mk]
);
break;
}
}
if (mk == -1) {
alert("Sorry!, This ID is not in out records...");
}
} while (mk == -1);
var updateChoice = parseInt(
prompt(
"What do you want to UPDATE in the Records ? \n1.NAME \n2.NUMBER \nEnter the choice. "
)
);
if (updateChoice == 1) {
do {
var na = prompt("Enter New Name: (Atleast 3 characters)");
} while (na.length < 3);
nam[mk] = na;
} else if (updateChoice == 2) {
do {
var num = parseInt(
prompt("Enter New Number: (Number should be of 10 digits)")
);
} while (num.toString().length != 10);
number[mk] = num;
} else {
alert("Please select appropriate Update choice. Thank You!");
}
alert(
"ID=" +
id[mk] +
"\nName=" +
nam[mk] +
"\nNumber=" +
number[mk] +
"\nEmail=" +
email[mk] +
"\nBirth Date=" +
birthDate[mk] +
"\nPrice=" +
price[mk] +
"\nQuantity=" +
quantity[mk] +
"\nSum Total=" +
sumTotal[mk] +
"\nTotal=" +
total[mk]
);
} else if (choice == 5) {
//----------------------------DELETE--------------------------------------
do {
var mk = -1;
var deleteID = parseInt(prompt("Enter the ID for deletion: "));
for (var i = 0; i < n; i++) {
if (deleteID == id[i]) {
mk = i;
break;
}
}
} while (mk == -1);
nam.splice(mk, 1);
number.splice(mk, 1);
email.splice(mk, 1);
password.splice(mk, 1);
birthDate.splice(mk, 1);
price.splice(mk, 1);
quantity.splice(mk, 1);
sumTotal.splice(mk, 1);
total.splice(mk, 1);
for (let i = 0; i < n; i++) {
alert(
"ID=" +
i +
"\nName=" +
nam[i] +
"\nNumber=" +
number[i] +
"\nEmail=" +
email[i] +
"\nBirth Date=" +
birthDate[i] +
"\nPrice=" +
price[i] +
"\nQuantity=" +
quantity[i] +
"\nSum Total=" +
sumTotal[i] +
"\nTotal=" +
total[i]
);
}
} else if (choice == 6) {
alert("Thank You! for visiting our system...");
doWhile = 1;
} else {
alert("Please select appropriate choice. Thank You!");
}
} while (doWhile == 0);
</script>