-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.js
More file actions
1679 lines (1499 loc) · 42.9 KB
/
style.js
File metadata and controls
1679 lines (1499 loc) · 42.9 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
//basic code start
alert("Hello Google");
console.log("Hello World");
document.write("I love Bangladesh");
//javascript Keywords:
//break,case,catch,continue,debugger,default,delete,do,
//else,finally,for,function,if,in,instanceof,new,return,
//switch,this,throw,try,typeof,var,void,while,with.
typeof("Johirul"); //string
typeof(234); //number
typeof(true); //boolean
typeof(false); //boolean
var name = "Johirul";
document.write(name);
var name = "Islam";
document.write(name);
var name = "Johirul";
var name = "Islam";
document.write(name); //last variable print- Islam
var name = "Johrul Islam";
var age = 23;
document.write(name);
document.write(age);
var name;
var age;
name = "johirul";
age = 23;
document.write(name);
document.write(age);
var name, age, address;
name = " johirul";
age = 23;
address = "Netrakona";
document.write(name, age, address);
//basic code end
//number type
var num = 30;
console.log(typeof(num)); //number
var num = "30";
console.log(typeof(num)); //string
var num = true;
console.log(typeof(num)); //boolean
var num = false;
console.log(typeof(num)); //boolean
//convert type of number
var num = 40;
num = toString(num);
console.log(typeof(num)); //convert number to string
var num = "40";
num = parseInt(num);
console.log(typeof(num)); //convert string to number
var num = "40.23";
num = parseFloat(num);
console.log(typeof(num)); //convert string to number
//display number length
var num = 3.3567;
console.log(num.toFixed(1)); //print 3.4 --- Is calculated after the decimal
var num = 3.3567;
console.log(num.toFixed(2)); //print 3.36 --- Is calculated after the decimal
var num = 3.3567;
console.log(num.toPrecision(1)); //print 3 --- Total number is calculated
var num = 3.3567;
console.log(num.toPrecision(2)); //print 3.4 --- Total number is calculated
//convert type
console.log(Number("34")); //convert string to number
console.log(typeof(Number("34"))); //convert string to number type
console.log(Number("34.456")); //convert string to number
console.log(Number(true)); //print 1--- true value is 1
console.log(Number(false)); //print 0 -- false value is 0
//string concatenation
document.write("Johirul" + " Islam ");
var firstName = "Johirul";
var lastName = " Islam ";
var fullName = firstName + lastName;
document.write(fullName);
document.write("My Name Is " + fullName);
document.write("My Name Is " + fullName + "Soni ");
document.write("firstName : " + firstName + " lastName : " + lastName); //string concatenation
//text length
var text = "Bangladesh";
var len = text.length;
document.write(len); //print 10
document.write("Number of character " + len);
document.write("Number of character " + text.length);
var text = prompt("Enter your name : "); //prompt() function-- Take user input
var len = text.length;
document.write("Number of your name : " + len);
//text case
var text1 = "Bangladesh";
var text = text1.charAt(3); //variable.charAt(3) function-- print 3number character g
document.write(text); //print g
var text = text1.toUpperCase(); //variable.toUpperCase() function-- all letters will be capitalized
document.write(text); //print BANGLADESH
var text = text1.toLowerCase(); //variable.toLowerCase() function-- All letters will be lowercase
document.write(text); //print bangladesh
//word concat and character position
var text1 = "Bangladesh";
var text2 = " is a beautiful country";
var text = text1.concat(text2); //variable1.concat(variable2) function-- Adds two variables
document.write(text);
var text = text1.slice(3, 6); //variable.slice(num1, num2) function-- finding positions within a character
document.write(text); //print gla
//My task start
var firstName = prompt("Enter First Name");
var lastName = prompt("Enter Last Name");
var fullName = firstName + " " + lastName + "<br/>";
document.write(fullName);
var nameLen = fullName.length + "<br/>";
document.write(nameLen);
var nameUpper = fullName.toUpperCase();
document.write(nameUpper);
var namePos = fullName.slice(1, 2);
document.write(namePos);
//My tast end
//Arithmetic operator--- +, -, *, /, %, **, ++,--
var a = 5;
var b = 4;
var c = 10;
document.write(a + b); //print 9
document.write(a - b); //print 1
document.write(a * b); //print 20
document.write(a / b); //print 1.25
document.write(a % b); //print 1
document.write(a ** b); //print 625
document.write(c++); //print 10--- again c++ then get return 11
document.write(++c); //print 11------ again ++c then get return 12
document.write(c--); //print 10--- again c-- then get return 9
document.write(--c); //print 9---- again c++ then get return 8
//Assignment operator--- =, +=, -=, *=, /=, %=, **=
var a = 8;
a += 2;
document.write(a); //print 10
var a = 8;
a -= 2;
document.write(a); //print 6
var a = 8;
a *= 2;
document.write(a); //print 16
var a = 8;
a /= 2;
document.write(a); //print 4
var a = 8;
a %= 2;
document.write(a); //print 0
var a = 8;
a **= 2;
document.write(a); //print 64
var num1 = 30;
var num2 = 20;
var sum, sub;
sum = num1 + num2;
document.write("Addition = " + sum + "<br/>");
sub = num1 - num2;
document.write("Subtraction = " + sub);
var num1 = prompt("Enter First Number : ");
var num2 = prompt("Enter Second Number : ");
var num1 = parseInt(num1, 10);
var num2 = parseInt(num2, 10);
var sum, sub;
sum = num1 + num2;
document.write("Addition = " + sum + "<br/>");
sub = num1 - num2;
document.write("Subtraction = " + sub);
//My task start
var num1 = prompt("Enter First Number : ");
var num2 = prompt("Enter Second Number : ");
var num1 = parseInt(num1, 10);
var num2 = parseInt(num2, 10);
var sum, sub, mul, div, rem;
sum = num1 + num2;
document.write(num1 + " + " + num2 + " = " + sum + "<br/>");
sub = num1 - num2;
document.write(num1 + " - " + num2 + " = " + sub + "<br/>");
mul = num1 * num2;
document.write(num1 + " * " + num2 + " = " + mul + "<br/>");
div = num1 / num2;
document.write(num1 + " / " + num2 + " = " + div + "<br/>");
rem = num1 % num2;
document.write(num1 + " % " + num2 + " = " + rem + "<br/>");
//rectangle area
var base = prompt("Enter base number");
var height = prompt("Enter height number");
var area = base * height;
document.write("Area = " + area);
var base = parseInt(prompt("Enter base number"));
var height = parseInt(prompt("Enter height number"));
var area = (base * height) / 2;
document.write("Area = " + area);
//fahrenheit to celsius
var fahrenheit = prompt("Enter fahrenheit number = ");
var celsius = (fahrenheit - 32) * 5 / 9;
document.write("Celsius = " + celsius);
//celsius to fahrenheit
var celsius = prompt("Enter celsius number = ");
var fahrenheit = (celsius * (9 / 5) + 32);
document.write("Fahrenheit = " + fahrenheit);
//Relational operator--- >, >=, <, <=, ==, ===, !=, !==
var num1 = 20;
var num2 = 20;
var num3 = "20";
var rel = Array(num1 > num2, num1 >= num2, num1 < num2, num1 <= num2);
var rel1 = num1 == num2; //== This symbol will check the same value
var rel2 = num1 == num3;
var rel3 = num1 === num2; //=== This symbol will check the same value and same data type
var rel4 = num1 === num3;
var rel5 = num1 != num2;
var rel6 = num1 !== num2;
var rel7 = num1 !== num3;
document.write(rel + "<br/>"); //print false,true,false,true
document.write(rel1 + "<br/>"); //print true- check same value
document.write(rel2 + "<br/>"); //print true- check same value not data type
document.write(rel3 + "<br/>"); //print true- check same value and same data type
document.write(rel4 + "<br/>"); //print false- check same value and not same data type
document.write(rel5 + "<br/>"); //print false- check value not equal
document.write(rel6 + "<br/>"); //print false- check value and data type not equal
document.write(rel7 + "<br/>"); //print true- check value and data type not equal
//Logical operator--- &&, ||, !
var num1 = 50;
var num2 = 30;
var num3 = 20;
//logical and operator &&
var logiAnd1 = num1 > num2 && num1 > num3; //All conditions must match
var logiAnd2 = num2 > num1 && num2 > num3; //All conditions must match
var logiAnd3 = num3 > num1 && num3 > num2; //All conditions must match
document.write(logiAnd1); //print ture--- all conditions match
document.write(logiAnd2); //print false--- all conditions not match
document.write(logiAnd3); //print false--- all conditions not match
//logical or operator ||
var logiOr1 = num1 > num2 || num1 > num3; //Any one condition must be matched
var logiOr2 = num2 > num1 || num2 > num3; //Any one condition must be matched
var logiOr3 = num3 > num1 || num3 > num2; //Any one condition must be matched
document.write(logiOr1); //print true--- Matching any one condition
document.write(logiOr2); //print true--- Matching any one condition
document.write(logiOr3); //print false--- Not matching any one condition
//logical not operator !
var logiNot1 = num1 > num2;
var logiNot2 = num1 < num2;
document.write(!logiNot1); //print false--- num1 is greater than num2--Conditions not match
document.write(!logiNot2); //print true--- num1 is less than num2--Conditions match
//if,else if, else
//number even odd
var num = 5;
if (num % 2 == 0)
document.write("Even");
else
document.write("Odd");
//positive negetive number
var num = prompt("Enter a number: ");
if (num > 0)
document.write("Positive");
else if (num < 0)
document.write("Negetive");
else
document.write("Zero");
//My task-result sheet
var marks = prompt("Enter your marks: ");
if (marks > 100 || marks < 0) {
document.write("Invalid Marks");
} else if (marks >= 80 && marks <= 100) {
document.write("Your Grade : A+");
} else if (marks >= 70 && marks <= 79) {
document.write("Your Grade : A");
} else if (marks >= 60 && marks <= 69) {
document.write("Your Grade : A-");
} else if (marks >= 50 && marks <= 59) {
document.write("Your Grade : B");
} else if (marks >= 40 && marks <= 49) {
document.write("Your Grade : C");
} else if (marks >= 33 && marks <= 39) {
document.write("Your Grade : D");
} else {
document.write("You are FAIL");
}
//Determine the largest number of three numbers
var num1 = prompt("Enter First Number : ");
var num2 = prompt("Enter Second Number : ");
var num3 = prompt("Enter Third Number : ");
if (num1 > num2 && num1 > num3) {
document.write("Large number : " + num1);
} else if (num2 > num1 && num2 > num3) {
document.write("Large number : " + num2);
} else {
document.write("Large number : " + num3);
}
//Determine vowel and consonant
var letter = prompt("Enter a letter : ");
letter = letter.toLowerCase();
if (letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u") {
document.write("Letter is Vowel");
} else {
document.write("Letter is Consonant");
}
//Switch
//digit spelling
var digit = prompt("Enter any digit: ");
switch (digit) {
case "0":
document.write("Zero");
break;
case "1":
document.write("One");
break;
case "2":
document.write("Two");
break;
case "3":
document.write("Three");
break;
case "4":
document.write("Fore");
break;
case "5":
document.write("Five");
break;
case "6":
document.write("Six");
break;
case "7":
document.write("Seven");
break;
case "8":
document.write("Eight");
break;
case "9":
document.write("Nine");
break;
case "10":
document.write("Ten");
break;
default:
document.write("Invalid Number");
}
//My task- determine vowel and consonant
var letter = prompt("Enter any letter");
letter = letter.toLowerCase();
switch (letter) {
case "a":
case "e":
case "i":
case "o":
case "u":
document.write("Vowel");
break;
default:
document.write("Consonant");
}
//for loop statment
var x;
for (x = 1; x <= 10; x++) {
document.write(" " + x); //print 1 2 3 4 5 6 7 8 9 10
}
for (x = 2; x <= 10; x = x + 2) {
document.write(" " + x); //print 2 4 6 8 10--- even number
}
for (x = 1; x <= 9; x = x + 2) {
document.write(" " + x); //print 1 3 5 7 9--- odd number
}
for (x = 10; x >= 1; x--) {
document.write(" " + x); //print 10 9 8 7 6 5 4 3 2 1
}
//determine numbers sum using for loop statment
var x;
var sum = 0;
for (x = 1; x <= 10; x++) {
sum = sum + x;
}
document.write(sum); //print 55--- (1-10) numbers sum
//Take user input numbers sum for loop statment
var x;
var s = parseInt(prompt("Enter start number: "));
var e = parseInt(prompt("Enter end number: "));
var sum = 0;
for (x = s; x <= e; x = x + 1) {
sum = sum + x;
}
document.write(sum);
//while loop statment
var i = 1;
while (i <= 5) {
document.write(" " + i);
i = i + 1;
}
//determine numbers sum using while loop statment
var i = 1;
var sum = 0;
while (i <= 5) {
sum = sum + i;
i = i + 1;
}
document.write(sum); //print 15--- (1-5) numbers sum
//My Task
var i = 1;
var sum = 0;
while (i <= 50) {
if (i % 3 == 0 && i % 5 == 0) {
document.write(" " + i);
sum = sum + i;
}
i = i + 1;
}
document.write(" Sum: " + sum);
//Take user input numbers sum while loop statment
var s = parseInt(prompt("Enter start number: "));
var e = parseInt(prompt("Enter end number: "));
var i = s;
sum = 0;
while (i <= e) {
sum = sum + i;
i = i + 1;
}
document.write(" " + sum);
//do while loop statment
var i = 1;
do {
document.write(" " + i);
i++;
} while (i <= 20);
//for loop use break
var i;
for (i = 1; i <= 100; i++) {
if (i == 10) {
break;
}
document.write(" " + i); //print 1 2 ...... 9
}
//for loop use continue
var i;
for (i = 1; i <= 50; i++) {
if (i == 10) {
continue;
}
document.write(" " + i);
}
var i;
for (i = 1; i <= 50; i++) {
if (i % 2 == 0) { //Odd number
continue;
}
document.write(" " + i);
}
var i;
for (i = 1; i <= 50; i++) {
if (i % 2 !== 0) { //Even number
continue;
}
document.write(" " + i);
}
//Ternary operator//
var num = Number(prompt("Enter a number : "));
var result = num > 0 ? "Positive" : num < 0 ? "Negetive" : "Zero";
document.write(result);
//My task--select the largest and smallest number by the ternary operator
var num1 = Number(prompt("Enter a first number : "));
var num2 = Number(prompt("Enter a second number : "));
var num3 = Number(prompt("Enter a third number : "));
var largNum = num1 > num2 && num1 > num3 ? document.write("Large number: " + num1) : num2 > num1 && num2 > num3 ? document.write("Large number: " + num2) : num3 > num1 && num3 > num2 ? document.write("Large number: " + num3 + "<br/>") :
document.write(largNum);
var smallNum = num1 < num2 && num1 < num3 ? document.write("Small number: " + num1) : num2 < num1 && num2 < num3 ? document.write("Small number: " + num2) : num3 < num1 && num3 < num2 ? document.write("Small number: " + num3) :
document.write(smallNum);
//function
function sqaure() {
var num = 5;
var result = num * num;
document.write("sqaure : " + result + "<br/>");
}
sqaure(); //print 25
function sqr(num) {
var result = num * num;
document.write("sqaure : " + result + "<br/>");
}
sqr(6); //print 36
function sqar(num1, num2) {
var result = num1 * num2;
document.write("sqaure : " + result + "<br/>");
}
sqar(4, 5); //print 20
function sum(num1, num2) {
var result = num1 + num2;
document.write("Sum : " + result + "<br/>");
}
sum(23, 27); //print 50
function sup(num1, num2) {
var result = num1 - num2;
return result;
}
var x = sup(9, 7);
document.write(x); //print 2
//My task-- calculator by user input
var n1 = Number(prompt("Enter first number : "));
var n2 = Number(prompt("Enter second number : "));
function addition(num1, num2) {
var result = num1 + num2;
document.write("Addition : " + result + "<br/>")
}
function subtraction(num1, num2) {
var result = num1 - num2;
document.write("Subtraction : " + result + "<br/>")
}
function multiple(num1, num2) {
var result = num1 * num2;
document.write("Multiple : " + result + "<br/>")
}
function divisition(num1, num2) {
var result = num1 / num2;
document.write("Divisition : " + result + "<br/>")
}
function remainder(num1, num2) {
var result = num1 % num2;
document.write("Remainder : " + result + "<br/>")
}
addition(n1, n2);
subtraction(n1, n2);
multiple(n1, n2);
divisition(n1, n2);
remainder(n1, n2);
//Array method
var names = new Array(5);
names[0] = "johirul";
names[1] = "Sany";
names[2] = "julfa";
names[3] = "samin";
names[4] = "hridoy";
document.write(names[3]); //print samin
document.write(names);
var names = ["johirul", "sany", "julfa", "samin", "hridoy"];
document.write(names[3]); //print samin
document.write(names);
//array push --- last name add
var names = ["johirul", "sany", "julfa", "samin", "hridoy"];
names.push("ashik"); //Another name will be added
document.write(names[5]); //print ashik
document.write(names);
//array unshift --- first name add
var names = ["sany", "julfa", "hridoy"];
names.unshift("johirul");
document.write(names);
//array pop --- last name remove
var names = ["johirul", "sany", "julfa", "samin", "hridoy"];
names.pop(); //last name remove
document.write(names);
//array shift --- first name remove
var names = ["johirul", "sany", "julfa"];
names.shift();
document.write(names); //first name remove
//array concat
var country1 = ["Bangladesh", "canada"];
var country2 = ["japan", "nepal"];
var country = country1.concat(country2);
document.write(country);
//array splice --- new name adding
var names = ["johirul", "sany", "ashik"];
names.splice(2, 0, "julfa", "hridoy");
document.write(names);
//array splice --- name removing
var names = ["johirul", "sany", "julfa", "hridoy", "ashik"];
names.splice(1, 2);
document.write(names);
//array slice --- name removing
var names = ["johirul", "sany", "julfa", "hridoy", "ashik"];
var newArray = names.slice(1);
document.write(newArray);
//array sort --- name sorting
var names = ["johirul", "sany", "julfa", "hridoy", "ashik"];
var sortNames = names.sort();
document.write(sortNames);
//array number sort --- number sorting
var numbers = [23, 1, 34, 43, 12, 23, 53, 56, 67];
numbers.sort(function(a, b) {
return a - b;
})
document.write(numbers);
//array number reverse --- number reverseing
var numbers = [23, 1, 34, 43, 12, 23, 53, 56, 67];
numbers.sort(function(a, b) {
return b - a;
})
document.write(numbers);
//array reverse --- name reversing
var names = ["johirul", "sany", "julfa", "hridoy", "ashik"];
var sortNames = names.sort();
names.reverse();
document.write(sortNames);
//loop array
var num = [10, 20, 30, 40, 50];
for (var i = 0; i < 5; i++) {
document.write(" " + num[i]);
}
//loop array sum
var num = [10, 20, 30, 40, 50];
var sum = 0;
for (var i = 0; i < 5; i++) {
document.write(" " + num[i]);
sum = sum + num[i];
}
document.write(" Sum : " + sum);
//loop array sum -- user input
var num = new Array();
for (var i = 0; i < 5; i++) {
num[i] = parseInt(prompt("Enter a number : "));
}
var sum = 0;
for (var i = 0; i < 5; i++) {
document.write(num[i]);
sum = sum + num[i];
}
document.write(" sum : " + sum);
//object method --- multiple value store
var student1 = {
name: "johirul islam",
age: 23,
lang: ["Bengali", "English", "Hindi"]
}
document.write(student1.name);
//object constructor add
function Student(name, age, lang) {
this.name = name;
this.age = age;
this.lang = lang;
this.display = function() {
document.write(this.name);
document.write(this.age);
document.write(this.lang);
}
}
var student1 = new Student("johirul", 23, ["Bengali", "English", "Hindi"]);
var student2 = new Student("sany", 21, ["hindi", "bangla", "english"]);
var student3 = new Student("hridoy", 20, ["arabia", "hindi", "bangla"]);
student1.display();
student2.display();
student3.display();
//object constructor add other method
class Student {
constructor(name, age, lang) {
this.name = name;
this.age = age;
this.lang = lang;
this.display = function() {
document.write(this.name);
document.write(this.age);
document.write(this.lang);
};
}
}
var student1 = new Student("johirul", 23, ["Bengali", "English", "Hindi"]);
var student2 = new Student("sany", 21, ["hindi", "bangla", "english"]);
var student3 = new Student("hridoy", 20, ["arabia", "hindi", "bangla"]);
student1.display();
student2.display();
student3.display();
class myClass {
hello() {
console.log("Hello world");
}
}
var obj = new myClass();
obj.hello();
//static mode
class myClass {
static hello() {
console.log("Hello world");
}
}
myClass.hello();
//class inheritance
class parent {
hello1() {
console.log("Hello One function");
}
hello2() {
console.log("Hello two function");
}
}
class child extends parent {
}
var obj = new child();
obj.hello1();
obj.hello2();
class parent {
hello1() {
console.log("Hello One function");
}
hello2() {
console.log("Hello two function");
}
}
class child extends parent {
demo() {
super.hello1();
super.hello2();
}
}
var obj = new child();
obj.demo();
//math object
//math sqrt
var x = Math.sqrt(25);
document.write(x); //print 5
//math abs
var x = Math.abs(-5);
document.write(x); //print 5
//math sin
var x = Math.sin(2);
document.write(x); //print 0.9092974268256817
//math pow
var x = Math.pow(2, 4);
document.write(x); //print 16
//math floor
var x = Math.floor(2.4);
document.write(x); //print 2
//math ceil
var x = Math.ceil(4.8);
document.write(x); //print 5
//math round
var x = Math.round(4.5);
document.write(x); //print 5 --- (.5-.9)
//math round
var x = Math.round(4.4);
document.write(x); //print 4 --- (.1-.4)
//math max
var x = Math.max(23, 45, 2, 34, 56);
document.write(x); //print 56
//math min
var x = Math.min(23, 43, 12, 45, 22, );
document.write(x); //print 12
//math random
var x = Math.random();
document.write(x); //print random number
//create guessing game
var numOfWon = 0;
var numOfLost = 0;
for (var i = 1; i <= 10; i++) {
var guessNum = parseInt(prompt("Enter a number from 1 to 10 : "));
var randomNum = Math.floor(Math.random() * 5) + 1;
if (guessNum == randomNum) {
console.log("You have won");
numOfWon++;
} else {
console.log("You have lost. Random number was " + randomNum);
numOfLost++;
}
}
console.log("Number of win : " + numOfWon);
console.log("Number of lost : " + numOfLost);
//Date object
var date = new Date();
document.write(date);
var year = date.getFullYear();
document.write(year);
var month = date.getMonth();
document.write(month);
var currentDate = date.getDate();
document.write(currentDate);
var currentDay = date.getDay();
document.write(currentDay);
var currentHour = date.getHours();
document.write(currentHour);
var currentMinute = date.getMinutes();
document.write(currentMinute);
var currentSecond = date.getSeconds();
document.write(currentSecond);
var currentMiliSecond = date.getMilliseconds();
document.write(currentMiliSecond);
var time = date.getTime();
document.write(time);
//how to select html element
//getElementById() --- innerHTML
//<h1 id="heading1">Hello World</h1>
document.getElementById("heading1").innerHTML = "Hello Google";
//getElementsByClassName() --- innerHTML
//<h1 class="heading2">Hello Bangladesh</h1>
//<h1 class="heading2">Hello Bangladesh</h1>
document.getElementsByClassName("heading2")[1].innerHTML = "Hello Canada";
//getElementsByTagName() --- innerHTML
//<h1>Hello German</h1>
document.getElementsByTagName("h1")[3].innerHTML = "Hello Japan";
//querySelector() --- innerHTML
//<h2 id="query1">This is Bangladesh</h2>
//<h2 class="query2">This is canada</h2>
document.querySelector("#query1").innerHTML = "This is query change one";
document.querySelector(".query2").innerHTML = "This is query change two";
//<h3>This is japan</h3>
document.querySelector("h3").innerHTML = "This is query change three";
//<a href="#">Link 0</a>
document.querySelector("a").innerHTML = "Link change one";
//<ul>
// <li><a href="#">Link 1</a></li>
//</ul>
document.querySelector("li a").innerHTML = "Link change two";
//<div class="myDiv">
// <a href="#">Link 2</a>
//</div>
document.querySelector("div a").innerHTML = "Link change three";
//querySelectorAll() --- innerHTML
//<p>This is paragraph</p>
document.querySelectorAll("p")[0].innerHTML = "Paragraph text change";
//button, onclick, function() --- innerHTML
function myButtonId() {
document.querySelector("#buttonId").innerHTML = "Lorem ipsum dolor sit amet consectetur adipisicing elit. Iste, est!"
}
function myButtonCls() {
document.querySelector(".buttonCls").innerHTML = "Lorem ipsum dolor sit amet consectetur adipisicing elit.";
}
function htmlBtn() {
document.querySelector("#btnImg").src = "img/html.png"
}
function cssBtn() {
document.querySelector("#btnImg").src = "img/css.png";
}
function jsBtn() {
document.querySelector("#btnImg").src = "img/javascript.png";
}
//getElementsByTagName() --- style,href,title
//<a href="#">Link 3</a>
document.getElementsByTagName("a")[3].style.textDecoration = "none";
document.getElementsByTagName("a")[3].href = "https://github.com/johirulshaky/";
document.getElementsByTagName("a")[3].title = "Github Profile";
document.getElementsByTagName("a")[3].style.fontSize = "25px";
document.getElementsByTagName("a")[3].style.color = "red";
document.getElementsByTagName("a")[3].style.textShadow = "1px 2px 3px green";
document.getElementsByTagName("a")[3].style.border = "1px solid gray";
document.getElementsByTagName("a")[3].style.fontWeight = "bold";
document.getElementsByTagName("a")[3].style.textTransform = "uppercase";
//create html element
//<div id="createElement">
//<h4>Create Element1</h4>
//<h4>Create Element2</h4>
//</div>
document.getElementById("createElement").appendChild(document.createElement("h4").appendChild(document.createTextNode("Create last Element by javascript")));
//remove html element
document.getElementById("createElement").removeChild(document.getElementsByTagName("h4")[0]);
//Create HTML elements before specific tags
document.getElementById("createElement").insertBefore(document.createElement("h4").appendChild(document.createTextNode("Create HTML elements before specific tags")), document.getElementsByTagName("h4")[0]);
//create html elements before specific tags --- other method
var myDiv = document.getElementById("createElement");
var heading = document.createElement("h4");
var textHead = document.createTextNode("Create HTML elements before specific tags 2");
heading.appendChild(textHead);
var headingN = document.getElementsByTagName("h4")[0];
myDiv.insertBefore(heading, headingN);
//add,replace and remove class in html element
document.getElementById("createElement").classList;
document.getElementById("createElement").classList.add("myClass");
document.getElementById("createElement").classList.replace("myClass", "listClass");
document.getElementById("createElement").classList.remove("listClass");
//javascript click image slider
var photos = ["img/html.png", "img/css.png", "img/javascript.png", "img/jquery.png"];
var imgTag = document.querySelector("img");
var count = 0;
function next() {
count++;
if (count >= photos.length) {
count = 0;
imgTag.src = photos[count];
} else {
imgTag.src = photos[count];
};
};
function prev() {
count--;
if (count < 0) {
count = photos.length - 1;
imgTag.src = photos[count];
}
imgTag.src = photos[count];
};
//HTML element style change by javascript
//classList.add(),classList.remove()
function addStyle() {
document.querySelector("#paraId").classList.add("paraClass");
//javascript build-in style
// var myStyle = document.querySelector("#paraId")
// myStyle.style.color = "red";
// myStyle.style.fontSize = "30px";
// myStyle.style.fontWeight = "bold";
// myStyle.style.fontStyle = "italic";
// myStyle.style.textShadow = "1px 2px 3px green";
// myStyle.style.background = "#f1f1f1";
// myStyle.style.width = "260px";
// myStyle.style.padding = "10px";
// myStyle.style.border = "1px solid #d1d1d1";
// myStyle.style.boxShadow = "0px 3px 10px 0px gray";
// myStyle.style.cursor = "pointer";
// myStyle.style.transition = ".5s"
};
function removeStyle() {
document.querySelector("#paraId").classList.remove("paraClass");
};
//addEvenListener()
document.querySelector("#clickStyle").addEventListener("click", function() {
document.querySelector("#clickStyle").classList.add("headingClass");
});