File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
+ < title > Document</ title >
8
+ </ head >
9
+ < body >
10
+
11
+ < button id ="btnClick "> CLICK</ button >
12
+ < button id ="btnWait "> WAIT</ button >
13
+ < button id ="btnCount "> COUNT</ button >
14
+ < div id ="result "> </ div >
15
+ < div id ="counter "> </ div >
16
+
17
+ < script >
18
+ let result = document . getElementById ( 'result' )
19
+ let counter = document . getElementById ( 'counter' )
20
+ let btnClick = document . getElementById ( 'btnClick' )
21
+ let btnWait = document . getElementById ( 'btnWait' )
22
+ let btnCount = document . getElementById ( 'btnCount' )
23
+ let c = 0
24
+
25
+ btnCount . onclick = function ( ) {
26
+ counter . innerText = ++ c
27
+ }
28
+
29
+ btnClick . onclick = function ( ) {
30
+ let start = new Date ( ) . getTime ( )
31
+ setTimeout ( ( ) => {
32
+ result . innerText = 'DONE!!!'
33
+ console . log ( 'Time taken = ' , new Date ( ) . getTime ( ) - start )
34
+ } , 2000 )
35
+ }
36
+
37
+ btnWait . onclick = function ( ) {
38
+ let start = new Date ( ) . getTime ( ) ;
39
+ while ( new Date ( ) . getTime ( ) - 3000 < start ) {
40
+ /* do nothing */
41
+ }
42
+ }
43
+ </ script >
44
+
45
+ </ body >
46
+ </ html >
Original file line number Diff line number Diff line change
1
+
2
+ function waitASec ( laterJob ) {
3
+ setTimeout ( laterJob , 1000 )
4
+ }
5
+
6
+ console . log ( 'started' )
7
+
8
+ waitASec ( function ( ) {
9
+ console . log ( 'job done' )
10
+ } )
11
+
12
+ console . log ( 'ended' )
You can’t perform that action at this time.
0 commit comments