-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
1167 lines (1143 loc) · 40.2 KB
/
index.js
File metadata and controls
1167 lines (1143 loc) · 40.2 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
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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//JS BASICS
// console.log("Jai Sree Ram");
// window .alert(`I am Nithin Sangsi`);
// document.getElementById("myh1").textContent = `Hello`;
// document.getElementById("myp").textContent=` i love js`;
//Variables
//NUMBERS
// let x; --declaration
// x=100; -assignment
// console.log(x);
// let age=25;
// let price=10.99;
// let cgpa=8.69;
//console.log(typeof age);--number
// console.log(age,price,gpa);
//console.log(`I have attained ${cgpa} after 3rd sem`);
//STRINGS
// let firstName=`Nithin`;
// let email=`nithinsangsi1234@gmail.com`;
// console.log(`my name is ${firstName} Sangsi and my email is ${email}`);
//BOOLEANS
// let online =true;
// console.log(`nithin is online in watsapp:${online}`);
// let student=true;
// document.getElementById("p1").textContent=age;
// document.getElementById("p2").textContent=cgpa;
// document.getElementById("p3").textContent=student;
// document.getElementById("p1").textContent=`my age is : ${age}`;
// document.getElementById("p2").textContent=`my cgpa as of now is : ${cgpa}`;
// document.getElementById("p3").textContent=`I am student : ${student}`;
//ARITHMETIC OPERATORS
// let students=20;
// students+1;
// students++;
// students+=1; //AUGUMENTED ASSIGNMENT OPERATOR
// console.log(students);
// let result=1+2*3+4**2; //OPERATOR PRECEDENCE parenthesis->pow->exponent->modulus->D->M->S->A
// console.log(resul t);
// let result1=12%5+8/2;
// console.log(result1);
//HOW TO ACCEPT USER INPUT
//1.EASY WAY
// let username;
// username=window.prompt("what is your Name?");
// console.log(username);
//PROFESSIONAL WAY .
// let username; --HTML TextBox takes input in live server and submites to console
// document.getElementById("mysubmit").onclick=function() {
// username=document.getElementById("mytext").value;
// console.log(username);
// }
// let username; changes the header to hello username
// document.getElementById("mysubmit").onclick=function() {
// username=document.getElementById("mytext").value;
// username=document.getElementById("myh1").textContent=`hello ${username}`;
// }
//TYPE CONVERSION
//without TC
// let age=window.prompt('how old are u ?');
// age+=1;
// console.log(age,typeof age);
//with TC
// let age=window.prompt('how old are u ?');
// age=Number(age);
// age+=1;
// console.log(age,typeof age);
// let x="puri";
// let y="puri";
// let z="puri";
// x=Number(x);
// y=String(y);
// z=Boolean(z);
// console.log(x,typeof x);
// console.log(y,typeof y);
// console.log(z,typeof z);
// let x="";
// let y="";
// let z="";
// x=Number(x);
// y=String(y);
// z=Boolean(z);
// console.log(x,typeof x);
// console.log(y,typeof y);
// console.log(z,typeof z);
// let x="0";
// let y="0";
// let z="0";
// x=Number(x);
// y=String(y);
// z=Boolean(z);
// console.log(x,typeof x);
// console.log(y,typeof y);
// console.log(z,typeof z);
// let x;
// let y;
// let z;
// x=Number(x);
// y=String(y);
// z=Boolean(z);
// console.log(x,typeof x);
// console.log(y,typeof y);
// console.log(z,typeof z);
// CONSTANTS
// const PI=3.14159; //easy way
// let radius;
// let circumference;
// PI=421.368; //error occurs in console
// radius=window.prompt("enter the radius of circle:");
// radius=Number(radius);
// circumference=2*PI*radius;
// console.log(circumference);
// const PI=3.14159; //professional way(every line is imp and should be in correct way )
// let radius;
// let circumference;
// document.getElementById("mysubmit").onclick=function(){
// radius=document.getElementById("mytext").value;
// radius=Number(radius);
// circumference=2 * PI * radius;
// document.getElementById("myh3").textContent=circumference + " cm";
// }
//COUNTER PROGRAM
// const decreasebtn=document.getElementById("decreasebtn");
// const resetbtn=document.getElementById("resetbtn");
// const increasebtn=document.getElementById("increasebtn");
// const countlabel=document.getElementById("countlabel");
// let count=0;
// increasebtn.onmousemove=function(){
// count++;
// countlabel.textContent=count;
// }
// resetbtn.onmousemove=function(){ //onclick can be used
// count=0;
// countlabel.textContent=count;
// }
// decreasebtn.onmousemove=function(){
// count--;
// countlabel.textContent=count;
// }
//MATH OBJECT
// let x=3.21;
// let y=2;
// let z=6;
// let p=-3.2562;
// let a,b,c,d,e,f,g,h,i,JS;
// console.log(a=Math.round(x))
// console.log(b=Math.floor(x))
// console.log(c=Math.ceil(x))
// console.log(d=Math.trunc(x))
// console.log(e=Math.pow(y,z))
// console.log(f=Math.sin(x))
// console.log(g=Math.sign(p)) // if negative number it return -1,if positive it eturns 1,and 0 if enterered 0
// console.log(h=Math.log(x))
// console.log(a=Math.sqrt(z))
// console.log(a=Math.abs(x))
// let max=Math.max(x,y,z);
// console.log(max)
//RANDOM NUMBER GENERATOR
// o=Math.random();
// console.log(o);
// let randomnum=Math.random(); //0-1 0.85553559865556-0.99999999999999 not 1
// console.log(randomnum);
// let randomnum1=Math.random()*6; //0.000000005955/2.525585855/5.4825626656 not 6
// console.log(randomnum1);
// let randomnum2=Math.floor(Math.random()*6); //0-5->0/1/2/3/4/5
// console.log(randomnum2);
// let randomnum3=Math.floor(Math.random()*6)+1; //1-5->1/2/3/4/5/6
// console.log(randomnum3);
// const min=50;
// const max=100;
// let randomnum4=Math.floor(Math.random()*max)+min; // 50-149
// console.log(randomnum4);
// let randomnum5=Math.floor(Math.random()*(max-min))+min; //50-99
// console.log(randomnum5);
//ROLL
// //1 time const mybtn=document.getElementById("mybtn");
// const min=1;
// const max=6;
// let randomnum;
// mybtn.onclick=function(){
// randomnum=Math.floor(Math.random()*max)+min; //1-6
// mylabel.textContent=randomnum;
// }
//3 times
// const mybtn=document.getElementById("mybtn");
// const label1=document.getElementById("label1");
// const label2=document.getElementById("label2");
// const label3=document.getElementById("label3");
// const min=1;
// const max=6;
// let randomnum1;
// let randomnum2;
// let randomnum3;
// mybtn.onclick=function(){
// randomnum1=Math.floor(Math.random()*max)+min ; //1-6
// randomnum2=Math.floor(Math.random()*max)+min ; //1-6
// randomnum3=Math.floor(Math.random()*max)+min ; //1-6
// label1.textContent=randomnum1;
// label2.textContent=randomnum2;
// label3.textContent=randomnum3;
// }
// IF STATEMENTS
// let isstudent =true; // if works well with boolean variables;
// if(isstudent){
// console.log("you are a student"); //if true
// }
// else{
// console.log("you are not a student"); //if false
// }
// let age=25; //nested-if
// let haslicense=true;
// if(age>=16){
// console.log("you can drive");
// if(haslicense){
// console.log("you have license"); //if true
// }
// else{
// console.log("you dont have license"); //if false
// }
// }
// else{
// console.log("you are not a student"); //if false
// }
// IF STATEMENTS
// const mytext=document.getElementById("mytext");
// const mysubmit=document.getElementById("mysubmit");
// const resultelement=document.getElementById("resultelement");
// let age;
// mysubmit.onclick=function()
// {
// age=mytext.value;
// age=Number(age);
// if(age>=18 && age<100){
// //console.log("u can drive");
// resultelement.textContent=`u can drive`;
// }
// else if(age == 0){
// //console.log("you are just born");
// resultelement.textContent=`you are just born`;
// }
// else if(age>100){
// //console.log("you are too old to drive");
// resultelement.textContent=`you are too old to drive`;
// }
// else if(age<0){
// //console.log("you people don't exist");
// resultelement.textContent=`you people don't exist`;
// }
// else{
// //console.log("you must be 18+to drive or else patrolling people will fine u and take money");
// resultelement.textContent=`you must be 18+ to drive or else patrolling people will fine u and take money`;
// }
// }
//CHECKED PROPERTY
// const mycheckbox=document.getElementById("mycheckbox");
// const viszbtn =document.getElementById("visabtn");
// const mastercardbtn=document.getElementById("mastercardbtn");
// const paypalbtn=document.getElementById("paypalbtn");
// const mysubmit=document.getElementById("mysubmit");
// const subresult=document.getElementById("subresult");
// const paymentresult=document.getElementById("paymentresult");
// mysubmit.onclick=function()
// {
// if(mycheckbox.checked){
// subresult.textContent=`You Are Subscribed`
// }
// else{
// subresult.textContent=`You Are Not Yet Subscribed`
// }
// if(visabtn.checked){
// paymentresult.textContent=`You Paid With Visa`
// }
// else if(mastercardbtn.checked){
// subresult.textContent=`You Paid With Mastercard`
// }
// else if(paypal.checked){
// paymentresult.textContent=`You Paid With PayPal`
// }
// else{
// paymentresult.textContent=`You Must Select `
// }
// }
//TERNERAY OPERATOR
// let age=21;
// res=age>18?`You Are Adult`:`You Are Minor`;
// console.log(res)
// let isstudent=true;
// res=isstudent?`You Are Adult`:`You Are Minor`;
// console.log(res)
// let purchaseamount=125;
// let discount=purchaseamount>=100?10:0;
// console.log(`your total amount is Rupees ${purchaseamount-purchaseamount *(discount/100)}`)
//SWITCHES = can be an efficient replacement to many else if statements
// let testscore=98;
// let testgrade;
// switch (true){
// case testscore>=90:
// testgrade='A';
// break;
// case testscore>=80:
// testgrade='B';
// break;
// case testscore>=70:
// testgrade='C';
// break;
// case testscore>=60:
// testgrade='D';
// break;
// default:
// testgrade="Fail";
// }
// console.log(testgrade);
//STRING METHODS
// let username="Nithin";
// a=username.lastIndexOf('i');
// console.log(a);
// b=username.indexOf('i');
// console.log(b);
// c=username.length;
// console.log(c);
// let username1=" NithinSangsi"
// d=username1.trim(); //to remove white spaces
// console.log(d);
// e=username.toUpperCase();
// console.log(e);
// f=username.toLowerCase('i');
// console.log(f);
// g=username.repeat(3);
// console.log(g);
// h=username.startsWith('n');
// console.log(h);
// i=username.endsWith('n');
// console.log(i);
// j=username.includes("in");
// console.log(j);
// let pnum="701-108-4252";
// pnum=pnum.replaceAll("-","");
// console.log(pnum);
// let k="123456789";
// a=k.padStart(12,"0");
// b=k.padEnd(15,"B");
// console.log(a)
// console.log(b);
//STRING SLICING
// const myname="Nithin Sangsi";
// let firstname=myname.slice(0,6);
// let a=myname.slice(-1);
// let b=myname.slice(-4);
// console.log(firstname);
// console.log(a);
// console.log(b);
// const email="NithinSangsi12345@gmail.com";
// let user =email.slice(0,email.indexOf("@"));
// let extension=email.slice(email.indexOf("@")); =@ is included
// let extension=email.slice(email.indexOf("@")+1); =@ is not included
// console.log(user,extension);
//METHOD CHANING
//NO METHOD CHANING
// let username=window.prompt("Enter the username name:");
// username=username.trim();
// let letter=username.charAt(0);
// letter=letter.toUpperCase();
// let extrachars=username.slice(1);
// extrachars=extrachars.toLowerCase();
// username=letter+extrachars;
// console.log(username);
//METHOD CHANING
// let username=window.prompt("Enter the username name:");
// username=username.trim().charAt(0).toUpperCase()
// +
// username.trim().slice(1).toLowerCase();
// console.log(username);
//LOGICAL OPERATORS
//AND
// const temp=21;
// if(temp > 0 && temp<=45){
// console.log(`toady is SUNNY`);
// }
// else{
// console.log(`today is CLOUDY`);
// }
//OR
// const temp=-21;
// if(temp < 0 || temp > 45){
// console.log(`toady is SUNNY`);
// }
// else{
// console.log(`today is CLOUDY`);
// }
//NOT
// const issunny=true; //normal as if-T,else-F
// if(!issunny){
// console.log(`it is sunny`);
// }
// else{
// console.log(`it is cloudy`);
// }
//STRICT INEQUALITY------imp
// = assignment operator
// == comparision operator (compare if values are equal)
// === strict equality operator(compare if the values and datatype are equal)
// != inequality operator
// !== strict inequality operator
// const PI=3.14159;
// if(PI == "3.14159"){ // == comparision (if only value matches is enough)
// console.log('That is PI');
// }
// else{
// console.log('that is not PI')
// }
// const PI=3.14159;
// if(PI === "3.14159"){ // === comparision (both datatype and value should match)
// console.log('That is PI');
// }
// else{
// console.log('that is not PI')
// }
// const PI=3.14159;
// if(PI != "3.14159"){ // (!=inequality operater)
// console.log('That is not PI');
// }
// else{
// console.log('that is PI')
// }
// const PI=3.14159;
// if(PI !== "3.14159"){ // (!=inequality operater)
// console.log('That is not PI');
// }
// else{
// console.log('that is PI')
// }
//WHILE LOOP--it repeats for unlimited number of times
// let username=`Nithin`;
// while (username == "Nithin"){
// console.log(`you did not enter ur name`);
// }
//console.log(`Hello ${username} !`);
// let username1='';
// while(username1==='' ){
// username1=window.prompt('Enter the username:');
// }
// console.log(`Hello ${username1}`);
// let loggedin=false;
// let username;
// let password;
// while(!loggedin){
// username=window.prompt("Enter the username:");
// password=window.prompt("Enter the password:");
// if(username ==="Nithin" && password==="12345"){
// loggedin=true;
// console.log("you are logged in");
// }
// else{
// console.log("invalid credentials,please enter correctly");
// }
// }
//FOR LOOPS--it repeats for limited number of times
// for(let i=0;i<=2;i++){
// console.log('hello')
// console.log(i);
// }
// for(let i=1;i<=20;i+=2){
// if(i==3){
// break;
// }
// else{
// console.log(i);
// }
// }
// for(let j=1;j<=20;j+=2){
// if(j==3){
// continue;
// }
// else{
// console.log(j);
// }
// }
//NUMBER GUESSING GAME--- //GOOD GAME WHERE MACHINE CHOOSES A RANDOM NUMBER IN THE GIVEN RANGE AND WE NEED YO GUESS THAT NUMBER
// const minnum=1;
// const maxnum=100;
// const answer=Math.floor(Math.random()*(maxnum-minnum+1)+minnum);
// let attempts=0;
// let guess;
// let running=true;
// while(running){
// guess=window.prompt(`Guess a number between ${minnum} To ${maxnum}`);
// if(isNaN(guess)){
// window.alert("please enter a valid number:");
// }
// else if(guess<minnum || guess >maxnum){
// window.alert("plese a valid number");
// }
// else{
// attempts++;
// if(guess<answer){
// window.alert("TOO LOW");
// }
// else if(guess>answer){
// window.alert("TOO HIGH");
// }
// else{
// window.alert(`CORRECT! The answer is ${answer} , It took you ${attempts} attempts`);
// running=false;
// }
// }
// }
//FUNCTIONS
// function happybirthday(){ //NO ARGS AND PAREMETERS
// console.log('Happy birthday to you!');
// console.log('Happy birthday to you my dear!');
// console.log('May god bless you!');
// console.log('Happy birthday to you!');
// }
// happybirthday();
// function happybirthday(bboy,god){ //ARGS AND PAREMETERS
// console.log(`Happy birthday to you ${bboy}!`);
// console.log('Happy birthday to you my dear!');
// console.log(`May god ${god} bless you!`);
// console.log('Happy birthday to you!');
// }
// happybirthday("Nithin","Hanuman");
//function iseven(number){
// if(number % 2 === 0){
// console.log(`the number ${number} is even`);
// }
// else{
// console.log(`the number ${number} is odd`);
// }
// return number % 2 === 0 ? true : false;
//}
//console.log(iseven(12));
// function isvalidemail(email){
// return email.includes("@") ? true : false;
// }
// console.log(isvalidemail("abcd@.com"));
//VARIABLE SCOPE---variable inside the function is a local variable and variable outside the function is global variable
//when both are present local is given the more scope
//TEMPERATURE CONVERSION PROGRAM
// const textbox=document.getElementById("textbox");
// const tofahrenheit=document.getElementById("tofahrenheit");
// const tocelsius=document.getElementById("tocelsius");
// const result=document.getElementById("result");
// let temp;
// function convert(){
// if(tofahrenheit.checked){
// temp=Number(textbox.value);
// // temp=Number(temp);
// temp=temp*(9/5)+32;
// result.textContent=temp.toFixed(1) +"°F";
// }
// else if(tocelsius.checked){
// temp=Number(textbox.value);
// // temp=Number(temp);
// temp=(temp-32)*(5/9);
// result.textContent=temp.toFixed(1) +"°C";
// }
// else{
// result.textContent="Select the unit";
// }
// }
//ARRAYS
// let fruits=["apple","cocunut","guava","banana"];
// console.log(fruits);
// let fruits=["apple","cocunut","guava","banana"];
// fruits.push("watermelon") //added at the last
// console.log(fruits);
// fruits.pop("watermelon")//removed from last
// console.log(fruits);
// fruits.pop()
// console.log(fruits);
// fruits.unshift("watermelon")
// console.log(fruits);
// a=fruits.length;
// console.log(a);
// console.log(fruits[3]);
// console.log(fruits[5]);
// console.log(fruits.sort());
// console.log(fruits.sort().reverse());
// console.log(fruits.indexOf("apple"));
// console.log(fruits.indexOf("pine"));
// for(let i=0;i<fruits.length;i++){
// console.log(fruits[i]);
// }
// for(let fruit of fruits)
// {
// console.log(fruit);
// }
//SPREAD OPERATOR (...variableName)
// let numbers=[1,2,3,4,5];
// let maximum=Math.max(numbers); //no output NAN
// let maximum=Math.max(...numbers); //output 5
// console.log(maximum);
// let user= "Nithin Sangsi";
// let letters1=[...user];
// let letters=[...user].join("-");
// console.log(letters);
// console.log(letters1);
// let fruits=["apple","cocunut","guava","banana"];
// let vegetables=["carrot","tomato","beans","gobi"];
// let foods=[...fruits,'milk','eggs',...vegetables];
// console.log(foods);
//REST PARAMETERS --- Opposite to the spread operator
// function openfridge(...foods){
// console.log(...foods);
//}
// function getFood(...foods){
// return foods;
//}
// const food1="rice";
// const food2="Daal";
// const food3="pickle";
// const food4="ghee";
// const food="Red Powder";
// }
// const foods=openfridge(food1,food2,food3,food4);
// const foods=getFood(food1,food2,food3,food4);
// console.log(foods);
// function sum(...numbers){
// let result=0;
// for (let number of numbers){
// result+=number;
// }
// return result;
// }
// const total =sum(1,2,3,4,5,6,7,8,9);
// console.log(total);
// function getavg(...numbers){
// let result=0;
// for (let number of numbers){
// result+=number;
// }
// return result/numbers.length;
// }
// const avg =getavg(1,2,3,4,5,6,7,8,9);
// console.log(avg);
// function combstr(...strings){
// // const fullname=("Nithin","Sangsi","Amma","Nanna","Akka");
// return strings.join("_");
// }
// const fullname=combstr("Nithin","Sangsi","Amma","Nanna","Akka");
// console.log(fullname);
//DICE ROLLER GAME
// function rolldice() {
// const ndice=document.getElementById("ndice").value;
// const diceresult=document.getElementById("diceresult");
// const diceimage=document.getElementById("diceimage");
// const values=[];
// const images=[];
// for(let i=0;i<ndice;i++){
// const value=Math.floor(Math.random()*6)+1;
// values.push(value);
// images.push(`<img src="dice_image/${value}.png" alt="dice${value}">`);
// }
// diceresult.textContent=`dice:${values.join(',')}`;
// diceimage.innerHTML=images.join('');
// }
//RANDOM PASSWORD GENERATER
// function generatepassword(length,includeuppercase,includelowercase,includenumbers,includesymbols)
// {
// const lowercasechars="abcdefghijklmnopqrstuvwxyz";
// const uppercasechars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// const numberchars="0123456789";
// const symbolchars="!@#$%^&*()_+/*-";
// let allowedchars="";
// let password="";
// allowedchars+=includelowercase?lowercasechars:"";
// allowedchars+=includeuppercase?uppercasechars:"";
// allowedchars+=includenumbers?numberchars:"";
// allowedchars+=includesymbols?symbolchars:"";
// if(length<=0){
// return(`password length must be atleast 1`);
// }
// if(allowedchars.length === 0){
// return(`atleast 1 set of characters must be selected`);
// }
// for(let i=0;i<length;i++){
// const randomindex=Math.floor(Math.random()*allowedchars.length);
// password+=allowedchars[randomindex];
// }
// return password;
// }
// const passwordlength=10;
// const includelowercase=true;
// const includeuppercase=true;
// const includenumbers=true;
// const includesymbols=true;
// const password=generatepassword(passwordlength,includeuppercase,includelowercase,includesymbols,includenumbers);
// console.log(`Generated password:${password}`);
//CALLBACK
// hello(leave);
// function hello(callback){
// console.log("hello");
// callback();
// }
// function goodbye(){
// console.log("goodbye");
// }
// function wait(){
// console.log("wait");
// }
// function leave(){
// console.log("leave");
//}
// sum(displaypage,1,2);
// function sum(callback,x,y){
// let result=x+y;
// callback(result);
// }
// function displaypage(result){
// document.getElementById("myh1").textContent=result;
// }
// function displayconsole(result){
// console.log(result);
// }
//ForEach
// let numbers=[1,2,3,4,5];
// numbers.forEach(display);
// function display(element){
// console.log(element);
// }
// let numbers=[1,2,3,4,5]; //doubling the number
// numbers.forEach(double);
// numbers.forEach(display);
// function double(element,index,array){
// array[index]=element*2;
// }
// function display(element){
// console.log(element);
// }
// let numbers=[1,2,3,4,5]; //cube of the number
// numbers.forEach(triple);
// numbers.forEach(display);
// function triple(element,index,array){
// array[index]=Math.pow(element,3);
// }
// function display(element){
// console.log(element);
// }
// let fruits=['apple','coconut','watermelon','guava']; //toUpperCase->✔️ touppercase❌
// fruits.forEach(UpperCase);
// fruits.forEach(display);
// function UpperCase(element,index,array){
// array[index]=element.toUpperCase();
// }
// function display(element){
// console.log(element);
// }
// let fruits=['apple','coconut','watermelon','guava']; //Captalize the first element
// fruits.forEach(Captalize);
// fruits.forEach(display);
// function Captalize(element,index,array){
// array[index]=element.charAt(0).toUpperCase() + element.slice(1);
// }
// function display(element){
// console.log(element);
// }
//.map()
// const numbers=[1,2,3,4,5,6];
// const squares=numbers.map(square);
// console.log(squares);
// function square(element){
// return Math.pow(element,2);
// }
// const students=['Nithin','Kanna','Harsha'];
// const upper=students.map(toUpperCase);
// console.log(upper);
// function toUpperCase(element){
// return element.toUpperCase();
// }
// const students=['Nithin','Kanna','Harsha']; //capitalize usin map dout
// const upper=students.map(Capitalize);
// console.log(upper);
// function Capitalize(element,index,array){
// array[index]=element.charAt(0).toUpperCase() + element.slice(1);
// }
// const dates=['2024-12-02','2023-05-25','2025-06-24'];
// const fdates=dates.map(fodates);
// console.log(fdates);
// function fodates(element){
// const parts=element.split('-');
// return `${parts[1]}/${parts[0]}/${parts[2]}`;
// }
//filter
// let numbers=[1,2,3,4,5,6];
// let evennum=numbers.filter(isEven);
// console.log(evennum);
// function isEven(element){
// return element%2==0;
// }
// const ages=[12,25,4,15,34,56];
// const adults=ages.filter(isadult);
// console.log(adults);
// console.log('you can vote');
// function isadult(element){
// return element>=18;
// }
// const words=['Nithin','Kanna','Harsha'];
// const swords=words.filter(getwords);
// console.log(swords);
// console.log('you can vote');
// function getwords(element){
// return element.length>=6;
// }
//reduce
// const prices=[5,30,41,25,31,21,12];
// const total=prices.reduce(sum);
// console.log(`$${total.toFixed(2)}`);
// function sum(accumulator,element){
// return accumulator+element;
// }
// const grades=[55,30,81,25,100,65,92];
// const max=grades.reduce(getmax);
// console.log(max,`marks`);
// function getmax(accumulator,element){
// return Math.max(accumulator,element);
// }
//function declaration
// function hello(){
// console.log(`Hello`);
// }
// setTimeout(hello,3000);
// function expression
// const hello=function(){
// console.log(`Hello`);
// }
// hello();
// setTimeout(function(){ //function is passed as an argument
// console.log(`Hello`);
// },3000);
//const numbers=[1,2,3,4,5];
// const squares=numbers.map(function(element){
// return Math.pow(element,2);
// });
// console.log(squares);
// const evennum=numbers.map(function(element){
// return element%2==0;
// });
// console.log(evennum);
// const total=numbers.reduce (function(accumulator,element){
// return accumulator+element;
// });
// console.log(total);
//Arrow Functions
// const hello =() => console.log('hello');hello();
// const hello =(name) => console.log(`Hello ${name}`);hello("Nithin");
// const hello =(name,age) => {console.log(`Hello ${name}`)
// console.log(`i am ${age} years old`)};hello("Nithin",21);
//setTimeout(() => console.log("Hello"),3000);
// const numbers=[1,2,3,4,5,6];
// const squares=numbers.map((element) => Math.pow(element,2));
// const evennum=numbers.filter((element) => element%2===0);
// const total=numbers.reduce((accumulator,element) => accumulator+element);
// console.log(squares);
// console.log(evennum);
// console.log(total);
//OOPS ------Objects
// const person={
// firstname:"Nithin",
// lastname:"Sangsi",
// age:21,
// isBillionaire:true,
// sayHello :() => console.log(`Hello i am ${this.firstname}`)
// }
// console.log(person.firstname);
// //console.log(this.firstname);
// console.log(person.lastname);
// console.log(person.age);
// console.log(person.isBillionaire);
// console.log(`i am ${person.firstname} ${person.lastname} , i am ${person.age} years old and i am youngest billionaire:${person.isBillionaire}`);
// person.sayHello();
//THIS this keyword is only used inside function statements
// const person={
// firstname:"Nithin",
// lastname:"Sangsi",
// age:21,
// isBillionaire:true,
// // sayHello :() => console.log(`Hello ${this.firstname}`) //this keyword will not work for arrow functions
// sayHello :function (){console.log(`Hello i am ${this.firstname} ${this.lastname}`)}
// }
// // console.log(person.firstname);
// // //console.log(this.firstname);
// // console.log(person.lastname);
// // console.log(person.age);
// // console.log(person.isBillionaire);
// console.log(`i am ${person.firstname} ${person.lastname} , i am ${person.age} years old and i am youngest billionaire:${person.isBillionaire}`);
// person.sayHello();
//Constructers
// function car(make,model,year,color){
// this.make=make, // , / ;
// this.model=model,
// this.year=year,
// this.color=color,
// this.drive=function(){
// console.log(`i love to drive ${this.model}`);
// }
// }
// const car1= new car("Rolls Royce","Phantom",2024,'white');
// console.log(car1.make);
// console.log(car1.model);
// console.log(car1.year);
// console.log(car1.color);
// car1.drive();
//Classes
// class product{
// constructor(name,price){
// this.name=name;
// this.price=price;
// }
// displayproduct(){
// console.log(`product name is : ${this.name}`);
// console.log(`product cost is : ${this.price} Rupees`);
// }
// calculatetotal(salestax){
// return this.price + (this.price*salestax);
// }
// }
// const p1=new product("T-Shirt",650);
// p1.displayproduct();
// //const salestax=0.05;
// const total=p1.calculatetotal(0.05);
// console.log(`total price(with tax) is ${total.toFixed(2)} Rupees`);
//Static keyword
// class mathutil{
// static PI=3.14159;
// }
// //const mathutil1=new mathutil();
// console.log(mathutil.PI);
// class mathutil{
// static PI=3.14159;
// static getdiameter(radius){
// return radius*2;
// }
// static circlecircumference(radius){
// return radius*2*this.PI;
// }
// static getarea(radius){
// return radius*radius*this.PI;
// }
// }
// console.log(mathutil.getdiameter(10));
// console.log(mathutil.circlecircumference(10));
// console.log(mathutil.getarea(10));
// class user{
// static usercount=0;
// constructor(username){
// this.username=username;
// user.usercount++;
// }
// }
// const u1=new user("Nithin");
// const u2=new user("Harsha");
// const u3=new user("Kanna");
// console.log(u1.username);
// console.log(u2.username);
// console.log(user.usercount);
// class user{
// static usercount=0;
// constructor(username){
// this.username=username;
// user.usercount++;
// }
// sayhello(){
// console.log(`Hello, my username is ${this.username}`);
// }
// static getusercount(){
// console.log(`There are ${user.usercount} users online now`);
// }
// }
// const u1=new user("Nithin");
// const u2=new user("Harsha");
// const u3=new user("Kanna");
// console.log(u1.username);
// u1.sayhello();
// console.log(u2.username);
// u2.sayhello();
// console.log(u3.username);
// u3.sayhello();
// console.log(user.usercount);
// console.log(user.getusercount());
//INHERITANCE
// class animal{