-
Notifications
You must be signed in to change notification settings - Fork 0
/
clacks2.html
777 lines (682 loc) · 31.1 KB
/
clacks2.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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett" />
<title>C>L>A>C>K>S</title>
<script type='text/javascript'>
/* ### This is just for fun :) ### */
var thisStep = 1;
function clacksColors()
{
var thisMessage = ["C",">","L",">","A",">","C",">","K",">","S"];
var oStr = "<p>";
for(i=0;i<thisMessage.length;i++)
{
if(thisStep == i)
{oStr += "<font color='#FF0000'>"+thisMessage[i]+"</font>";}
else
{oStr += thisMessage[i];}
}
oStr += "<p>";
document.getElementById('header').innerHTML = oStr;
if(thisStep == 10)
{
thisStep = 0;
}
else
{
thisStep++;
}
setTimeout(clacksColors, 500);
}
</script>
<script type='text/javascript'>
function yourFunction_1()
{
/* ### This is the main method of processing your arguments in C>L>A>C>K>S ### */
/* ### Here we define the types of arguments we want to pass in. ### */
/* ### The number of types acts as a count of how many arguments the function is expecting. ### */
/* ### You can call your TYPES whatever you like, as you will know what it is your expecting, so can process it accordingly in your custom validation functions. ### */
/* ### e.g. TYPE: DRAGON. VALUE: YES/NO...TYPE: BATH_LEVEL. VALUE: 50...and so on.... ### */
var types = ["NUMBER","STRING","STRING","STRING","STRING","NUMBER","NUMBER","STRING","CAKE","CAKE","CakE"];
/* ### We call our CLACKS_APPLY function here, sending the types and arguments arrays ### */
var CLACKS_CONFIRM = CLACKS_APPLY(types,arguments);
/* ### Here we deal with the return from CLACKS_APPLY (via the CLACKS_CONFIRM variable) ### */
/* ### If CLACKS_APPLY has returned true, then all is well in our functions world and we can continue to execute the function ### */
/* ### THE REST OF YOUR FUNCTION CODE WOULD GO HERE ### */
/* ### But for the sake of this example, we will just output to the screen ### */
/* ### *********************** START OF SCREEN DUMP *********************** ### */
if(CLACKS_CONFIRM == true)
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>All arguments are present and all match their types</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(arguments.length > types.length)
{
var twoFlower = arguments.length;
}
else
{
var twoFlower = types.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + types[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + arguments[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + types[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + arguments[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_1()</strong></td></tr></tbody></table>";
}
else
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>"+CLACKS_CONFIRM+"</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(arguments.length > types.length)
{
var twoFlower = arguments.length;
}
else
{
var twoFlower = types.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + types[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + arguments[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + types[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + arguments[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_1()</strong></td></tr></tbody></table>";
}
/* ### *********************** END OF SCREEN DUMP *********************** ### */
}
</script>
<script type='text/javascript'>
/* ### This is an alternative method of processing your arguments in C>L>A>C>K>S ### */
function yourFunction_2()
{
var AT = [];
var AV = [];
for(i=0;i<arguments.length;i++)
{
var tV = arguments[i].split(":");
AT.push(tV[0]);
AV.push(tV[1]);
}
var CLACKS_CONFIRM = CLACKS_APPLY(AT,AV);
/* ### Here we deal with the return from CLACKS_APPLY (via the CLACKS_CONFIRM variable) ### */
/* ### If CLACKS_APPLY has returned true, then all is well in our world and we can continue to execute the function ### */
/* ### THE REST OF YOUR FUNCTION CODE WOULD GO HERE ### */
/* ### But for the sake of this example, we will just output to the screen ### */
/* ### *********************** START OF SCREEN DUMP *********************** ### */
if(CLACKS_CONFIRM == true)
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>All arguments are present and all match their types</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_2()</strong></td></tr></tbody></table>";
}
else
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>"+CLACKS_CONFIRM+"</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_2()</strong></td></tr></tbody></table>";
}
/* ### *********************** END OF SCREEN DUMP *********************** ### */
}
</script>
<script type='text/javascript'>
/* ### This is an alternative method of processing your arguments in C>L>A>C>K>S ### */
function yourFunction_3()
{
var AT = [];
var AV = [];
myArguments = arguments[0].split(",");
for(i=0;i<myArguments.length;i++)
{
var tV = myArguments[i].split(":");
AT.push(tV[0]);
AV.push(tV[1]);
}
var CLACKS_CONFIRM = CLACKS_APPLY(AT,AV);
/* ### Here we deal with the return from CLACKS_APPLY (via the CLACKS_CONFIRM variable) ### */
/* ### If CLACKS_APPLY has returned true, then all is well in our world and we can continue to execute the function ### */
/* ### THE REST OF YOUR FUNCTION CODE WOULD GO HERE ### */
/* ### But for the sake of this example, we will just output to the screen ### */
/* ### *********************** START OF SCREEN DUMP *********************** ### */
if(CLACKS_CONFIRM == true)
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>All arguments are present and all match their types</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_3()</strong></td></tr></tbody></table>";
}
else
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='3' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>"+CLACKS_CONFIRM+"</th></tr>";
rtnMessage += "<tr><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='33%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='3'><center><strong>yourFunction_3()</strong></td></tr></tbody></table>";
}
/* ### *********************** END OF SCREEN DUMP *********************** ### */
}
</script>
<script type='text/javascript'>
/* ### This is an alternative method of processing your arguments in C>L>A>C>K>S ### */
function yourFunction_5()
{
console.log(arguments);
var AT = [];
var AP = [];
var AV = [];
//myArguments = arguments[0].split(",");
for(i=0;i<arguments.length;i++)
{
var tV = arguments[i].split(":");
AT.push(tV[0]);
AP.push(tV[1]);
AV.push(tV[2]);
}
var CLACKS_CONFIRM = CLACKS_APPLY_2(AT,AP,AV);
/* ### Here we deal with the return from CLACKS_APPLY (via the CLACKS_CONFIRM variable) ### */
/* ### If CLACKS_APPLY has returned true, then all is well in our world and we can continue to execute the function ### */
/* ### THE REST OF YOUR FUNCTION CODE WOULD GO HERE ### */
/* ### But for the sake of this example, we will just output to the screen ### */
/* ### *********************** START OF SCREEN DUMP *********************** ### */
if(CLACKS_CONFIRM == true)
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='4' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>All arguments are present and all match their types</th></tr>";
rtnMessage += "<tr><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Length</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 0px;font-weight:bold;'>" + AP[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 0px;font-weight:bold;'>" + AP[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='4'><center><strong>yourFunction_5()</strong></td></tr></tbody></table>";
}
else
{
var rtnMessage = "<table width='100%' style='border-radius:25px;' cellpadding='10' cellspacing='0'><tbody><tr><th colspan='4' style='border: 2px solid #FF0000;border-radius: 25px 25px 0px 0px'>"+CLACKS_CONFIRM+"</th></tr>";
rtnMessage += "<tr><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Index</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Type</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Length</td><td width='25%' style='border: 2px solid #FF0000;font-weight:bold;'>Argument</td></tr>";
if(AV.length > AT.length)
{
var twoFlower = AV.length;
}
else
{
var twoFlower = AT.length;
}
for(i=0;i<twoFlower;i++)
{
if(i == twoFlower-1)
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 25px;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 0px;font-weight:bold;'>" + AP[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 25px 0px;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
else
{
rtnMessage += "<tr><td style='border: 2px solid #FF0000;font-weight:bold;'>"+i+"</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AT[i] + "</td><td style='border: 2px solid #FF0000;border-radius: 0px 0px 0px 0px;font-weight:bold;'>" + AP[i] + "</td><td style='border: 2px solid #FF0000;font-weight:bold;'>" + AV[i] + "</td></tr>";
}
}
return rtnMessage + "<tr><td colspan='4'><center><strong>yourFunction_5()</strong></td></tr></tbody></table>";
}
/* ### *********************** END OF SCREEN DUMP *********************** ### */
}
</script>
<script type='text/javascript'>
/* ### This is the function that evaluates the arguments/types and sends them out to your custom validation functions for checking ### */
function CLACKS_APPLY(arg_types,arg_values)
{
/* ### Set up our KARMA ### */
var KARMA = true;
/* ### Check to see if there are as many arguments as types, if not, throw and error ### */
if(arguments[0].length !== arguments[1].length)
{
if(arguments[0].length<arguments[1].length)
{
return "CLACKS ERROR: There are more arguments than types.";
}
else
{
return "CLACKS ERROR: There are more types than arguments";
}
return;
}
/* ### Loop through the arguments and call custom functions to validate the arguments ### */
for(var gnu=0;gnu<arguments[0].length;gnu++)
{
/* ### So now we add some conditional checks so that we can process the arguments accordingly ### */
/* ### This one will check to see if the argument is a number or empty ### */
if(arguments[0][gnu].toUpperCase() === "NUMBER")
{
var KARMA = CLACKS_NUMBER(arguments[1][gnu]);
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
}
/* ### This one will check to see if the argument is text, not a number or empty ### */
if(arguments[0][gnu].toUpperCase() === "STRING")
{
var KARMA = CLACKS_TEXT(arguments[1][gnu]);
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
}
/* ### This one checks to see if it is a cake or empty... ### */
if(arguments[0][gnu].toUpperCase() === "CAKE")
{
var KARMA = CLACKS_CAKE(arguments[1][gnu]);
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
}
/* ### This one checks to see if it is a car or empty... ### */
if(arguments[0][gnu].toUpperCase() === "CAR")
{
var KARMA = CLACKS_CAR(arguments[1][gnu]);
if(KARMA !== true)
{
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
else
{
return KARMA;
}
}
}
/* ### This one checks to see if it is a Jackson Five or empty... ### */
if(arguments[0][gnu].toUpperCase() === "JACKSONFIVE")
{
var KARMA = CLACKS_JACKSONS(arguments[1][gnu]);
if(KARMA !== true)
{
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
else
{
return KARMA;
}
}
}
}
/* ### return the state of KARMA (true/false) to the function that called CLACKS_APPLY ### */
return KARMA;
}
</script>
<script type='text/javascript'>
/* ### This is the function that evaluates the arguments/patterns/types and sends them out to your custom validation functions for checking ### */
function CLACKS_APPLY_2(argTypes,argPattern,argValues)
{
/* ### Set up our KARMA ### */
var KARMA = true;
console.log(argTypes+":"+argPattern+":"+argValues);
/* ### Check to see if there are as many arguments as types, if not, throw and error ### */
if(arguments[0].length !== arguments[1].length)
{
if(arguments[0].length<arguments[2].length)
{
return "CLACKS ERROR: There are more arguments than types.";
}
else
{
return "CLACKS ERROR: There are more types than arguments";
}
return;
}
/* ### Loop through the arguments and call custom functions to validate the arguments ### */
for(var gnu=0;gnu<arguments[0].length;gnu++)
{
/* ### So now we add some conditional checks so that we can process the arguments accordingly ### */
/* ### This one will check to see if the type is a number and contains the correct number of digits ### */
if(arguments[0][gnu].toUpperCase() === "NUMBER_LENGTH")
{
/* ### Lets check the length before we send it off for verifying */
if(arguments[2][gnu].length !== parseInt(arguments[1][gnu]))
{
return "ERROR: Argument ("+gnu+") - Value entered does not contain "+arguments[1][gnu]+" digits";
}
else
{
var KARMA = CLACKS_NUMBER(arguments[2][gnu]);
}
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
}
/* ### This one will check to see if the type is a number and contains the correct number of digits within the range ### */
if(arguments[0][gnu].toUpperCase() === "NUMBER_RANGE")
{
/* ### We need to split argument[1] so that we can get the range */
var thisRange = arguments[1][gnu].split("-");
/* ### Lets check the length before we send it off for verifying */
if(arguments[2][gnu].length < parseInt(thisRange[0]) || arguments[2][gnu].length > parseInt(thisRange[1]))
{
return "ERROR: Argument ("+gnu+") - Value entered does not contain "+arguments[1][gnu]+" digits ("+arguments[2][gnu].length+")";
}
else
{
var KARMA = CLACKS_NUMBER(arguments[2][gnu]);
}
if(KARMA === false)
{
return "ERROR: Argument ("+gnu+") does NOT match its type, is invalid or is empty";
}
}
}
/* ### return the state of KARMA (true/false) to the function that called CLACKS_APPLY ### */
return KARMA;
}
</script>
<script type='text/javascript'>
/* ### This is a custom validation function to check if what we send it is a number or empty and respond accordingly ### */
function CLACKS_NUMBER(CLACK)
{
if(CLACK == "")
{
return false;
}
if(Number.isNaN(Number(CLACK)))
{
return false;
}
else
{
return true;
}
}
/* ### This is a custom validation function to check if what we send it is text, not a number or empty and respond accordingly ### */
function CLACKS_TEXT(CLACK)
{
if(CLACK === "")
{
return false;
}
else
{
isText = CLACKS_NUMBER(CLACK);
if(isText === false)
{
return true;
}
else
{
return false;
}
}
}
/* ### This is a custom validation function to check if what we send it is a cake, not a number(as we know it should be text) or empty and respond accordingly ### */
function CLACKS_CAKE(CLACK)
{
if(CLACK === "")
{
return false;
}
else
{
isText = CLACKS_NUMBER(CLACK);
if(isText === false)
{
if(CLACK.toUpperCase() === "CHOCOLATE" || CLACK.toUpperCase() === "CARROT" || CLACK.toUpperCase() === "SPONGE" || CLACK.toUpperCase() === "VICTORIA SPONGE")
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
/* ### This is a custom validation function to check if what we send it is a car, not a number(as we know it should be text) or empty and respond accordingly ### */
function CLACKS_CAR(CLACK)
{
if(CLACK === "")
{
return false;
}
else
{
isText = CLACKS_NUMBER(CLACK);
if(isText === false)
{
if(CLACK.toUpperCase() === "AUDI" || CLACK.toUpperCase() === "PORSCHE" || CLACK.toUpperCase() === "BMW" || CLACK.toUpperCase() === "LAND ROVER")
{
return true;
}
else
{
return CLACK + " is NOT a car!";
}
}
else
{
return false;
}
}
}
/* ### This is a custom validation function to check if what we send it is a member, or was a member of the Jackson Five, not a number(as we know it should be text) or empty and respond accordingly ### */
function CLACKS_JACKSONS(CLACK)
{
var JacksonFive = ["MICHAEL","JACKIE","JERMAINE","TITO","MARLON","RANDY"];
if(CLACK === "")
{
return false;
}
else
{
isText = CLACKS_NUMBER(CLACK);
if(isText === false)
{
for(j=0;j<JacksonFive.length;j++)
{
if(CLACK.toUpperCase() == JacksonFive[j])
{
console.log(CLACK+":"+JacksonFive[j]);
return true;
}
else
{
if(j==JacksonFive.length-1)
{
return "ERROR: "+CLACK+" was NOT or is NOT a member of the Jackson Five"; false;
}
}
}
}
else
{
return false;
}
}
}
</script>
</head>
<body onload='clacksColors();' style='background-color:#808080'>
<center>
<div id='header' style='font-family:arial;font-size: 2em; font-weight: bold'></div>
<div id="output_1" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_2A" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_2B" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_2C" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_3" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_4" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_5A" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
<div id="output_5B" style='border:2px solid #FF0000;border-radius: 25px;width:30%;padding:10px;font-family:arial;margin-bottom:15px;background-color:#F4F4F4'></div>
</center>
<script type='text/javascript'>
// ### Here we Command the yourFunction_1 function and pass it some arguments, then return the fruits of our labours to the screen.
document.getElementById("output_1").innerHTML = yourFunction_1("2.5","4th","World","three","Hello","49.97","1001","Testing","sponge","Carrot","Victoria Sponge");
// ### Here is another way we can COMMAND our function in C>L>A>C>K>S.
// ### We can pass the TYPES and ARGUMENTS in as paired arguments and then using a slightly different function - yourFunction2(), process the arguments.
document.getElementById("output_2A").innerHTML = yourFunction_2("NUMBER:476.5","STRING:476th","STRING:467 and a bit","STRING:more 467","STRING:and more 467","NUMBER:46.7","NUMBER:467467","STRING:Many 467","CAR:Land rover","CAR:Porsche","CAKE:Victoria Sponge");
// ### Here we are calling yourFunction_2 but using an array to hold our VALUES, with the TYPES being hardcoded into the COMMAND
var items_A = [];
items_A[0] = 481;
items_A[1] = "482nd";
items_A[2] = 483;
items_A[3] = "Chocolate";
document.getElementById("output_2B").innerHTML = yourFunction_2("NUMBER:"+items_A[0],"STRING:"+items_A[1],"NUMBER:"+items_A[2],"CAKE:"+items_A[3]);
// ### Here we are calling yourFunction_2 but using an array to hold our TYPES and VALUES
var items_B = [];
items_B[0] = {Type:"NUMBER:",Value:489};
items_B[1] = {Type:"STRING:",Value:"490th"};
items_B[2] = {Type:"NUMBER:",Value: 491};
items_B[3] = {Type:"CAKE:",Value:"Carrot"};
document.getElementById("output_2C").innerHTML = yourFunction_2(items_B[0]['Type']+items_B[0]['Value'],items_B[1]['Type']+items_B[1]['Value'],items_B[2]['Type']+items_B[2]['Value'],items_B[3]['Type']+items_B[3]['Value']);
// ### Here we are calling yourFunction_3, using an array to hold our TYPES and VALUES
var items_C = [];
items_C[0] = {Type:"NUMBER:",Value:406};
items_C[1] = {Type:"STRING:",Value:"407th"};
items_C[2] = {Type:"NUMBER:",Value: 408};
items_C[3] = {Type:"CAKE:",Value:"Victoria Sponge"};
items_C[4] = {Type:"JACKSONFIVE:",Value:"Michael"};
items_C[5] = {Type:"JACKSONFIVE:",Value:"TITO"};
items_C[6] = {Type:"CAR:",Value:"Chester"};
//items_C[7] = {Type:"JACKSONFIVE:",Value:"Dave"};
//items_C[8] = {Type:"CAKE:",Value:"Carrot"};
//items_C[9] = {Type:"CAR:",Value:"BMW"};
var myArguments = "";
for(i=0;i<items_C.length;i++)
{
if(i==items_C.length-1)
{
myArguments += items_C[i]['Type']+items_C[i]['Value'];
}
else
{
myArguments += items_C[i]['Type']+items_C[i]['Value']+",";
}
}
document.getElementById("output_3").innerHTML = yourFunction_3(myArguments);
// ### Only allow emails from .co.uk address
var varType = "EMAIL";
var varPattern = "co.uk"
var varValue = "myemail@myprovider.co.uk";
//document.getElementById("output_4").innerHTML = yourFunction_4(varType+":"+varPattern+":"+varValue,"EMAIL:.COM:clack@claks.com");
// ### Validate that we are sending a number and that it is 5 digits in length
varType_1 = "NUMBER_LENGTH";
varRange_1 = "5";
varValue_1 = "56789";
varType_2 = "NUMBER_LENGTH";
varRange_2 = "4";
varValue_2 = "999";
document.getElementById("output_5A").innerHTML = yourFunction_5(varType_1+":"+varRange_1+":"+varValue_1,varType_2+":"+varRange_2+":"+varValue_2);
// ### Validate that we are sending a number and that it between 6 and 10 digits in length
varType = "NUMBER_RANGE";
varRange = "6-10";
varValue = "1234567890";
document.getElementById("output_5B").innerHTML = yourFunction_5(varType+":"+varRange+":"+varValue);
// ### You get the idea...there are many ways you can construct your arguments (Values, Types/Values, etc, etc).
// ### Might be interested in seeing if I can collate the failures, rather than just bailing at the first one.
// ### At the moment, it only shows, in this example, that JANET is the fail point...not that Dave is also a fail point
// ### In fairness, it doesnt really matter as we should really mop up in a sequential manner anyway
</script>
<!--Author: Simon Bailey -->
</body>
</html>