File tree 6 files changed +98
-0
lines changed 6 files changed +98
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > Async-Callbacks</ title >
9
+ < link rel ="shortcut icon " href ="images/js-logo.png " type ="image/x-icon ">
10
+ </ head >
11
+
12
+ < body >
13
+ < h3 id ="textOne "> </ h3 >
14
+ < h3 id ="textTwo "> </ h3 >
15
+ < input id ="inpOne " value ="12 ">
16
+ < button onclick ="Disp() "> Click</ button >
17
+ < p id ="paraText "> </ p >
18
+ < script src ="script.js "> </ script >
19
+ </ body >
20
+
21
+ </ html >
Original file line number Diff line number Diff line change
1
+ /* This is a Simple Example of Function that are called upon each other
2
+ It also includes Callback functionality but we cannot control the result
3
+ */
4
+ function DisplayOne ( dispOne ) {
5
+ document . getElementById ( 'textOne' ) . innerHTML = dispOne ;
6
+ }
7
+
8
+ function Sum ( num1 , num2 ) {
9
+ let sum = num1 + num2 ;
10
+ return "Sum of " + num1 + " and " + num2 + " = " + sum ;
11
+ }
12
+ let result = Sum ( 99 , 2 ) ;
13
+ DisplayOne ( result ) ;
14
+
15
+ /*
16
+ To getting control over the function we use the following Example Below
17
+ Actual function of Callback()--Below
18
+ */
19
+
20
+ function DisplayTwo ( dispTwo ) {
21
+ document . getElementById ( 'textTwo' ) . innerHTML = dispTwo ;
22
+ }
23
+
24
+ function Mult ( num3 , num4 , callBack ) {
25
+ let mult = num3 * num4 ;
26
+ callBack ( "The Multiplication of " + num3 + " and " + num4 + " = " + mult ) ;
27
+ }
28
+ Mult ( 12 , 2 , DisplayTwo ) ;
29
+
30
+
31
+ function Disp ( ) {
32
+ var inpValue = document . getElementById ( 'inpOne' ) . value ;
33
+ document . getElementById ( 'paraText' ) . innerHTML = inpValue ;
34
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > Asynchronous</ title >
9
+ < link rel ="shortcut icon " href ="images/js-logo.png " type ="image/x-icon ">
10
+ </ head >
11
+
12
+ < body >
13
+ < h2 id ="textOne "> </ h2 >
14
+ < h2 id ="textTwo "> </ h2 >
15
+ < script src ="script.js "> </ script >
16
+ </ body >
17
+
18
+ </ html >
Original file line number Diff line number Diff line change
1
+ /*
2
+ In Asynchronous functions run parallel to each other which are called Asynchronous
3
+ Best example is setTimeOut()
4
+ and setInterval()
5
+ */
6
+
7
+ // Example of setTimeOut
8
+
9
+ function DisplayOne ( ) {
10
+ let text = "Hey There!" ;
11
+ document . getElementById ( 'textOne' ) . innerHTML = text ;
12
+ }
13
+
14
+ setTimeout ( DisplayOne , 2000 ) ; //Here we have called a function and also defined after how many miliseconds will the function load
15
+
16
+
17
+ // Example of setInterval()
18
+
19
+ function DispTwo ( ) {
20
+ let x = new Date ( ) ;
21
+ let time = x . getHours ( ) + " : " + x . getMinutes ( ) + " : " + x . getSeconds ( ) ;
22
+ document . getElementById ( 'textTwo' ) . innerHTML = time ;
23
+ }
24
+
25
+ setInterval ( DispTwo , 1000 ) ;
You can’t perform that action at this time.
0 commit comments