File tree 4 files changed +58
-3
lines changed
4 files changed +58
-3
lines changed Original file line number Diff line number Diff line change 5
5
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
6
< meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7
7
< title > Document</ title >
8
- < script defer src ="script.js "> </ script >
8
+ < script defer src ="script-createelement .js "> </ script >
9
9
</ head >
10
10
< body >
11
11
Original file line number Diff line number Diff line change
1
+ let list = document . getElementById ( 'list' )
2
+ let n = document . getElementById ( 'n' )
3
+ let print = document . getElementById ( 'print' )
4
+
5
+ print . onclick = function ( ) {
6
+ let start = new Date ( ) . getTime ( )
7
+
8
+
9
+ for ( let i = 1 ; i <= n . value ; i ++ ) {
10
+ let x = ''
11
+ if ( i % 3 == 0 ) x += 'fizz'
12
+ if ( i % 5 == 0 ) x += 'buzz'
13
+ if ( x == '' ) x = i
14
+
15
+ let item = document . createElement ( 'li' )
16
+ item . innerText = x
17
+ list . appendChild ( item )
18
+ }
19
+
20
+ let end = new Date ( ) . getTime ( )
21
+ console . log ( end - start )
22
+ }
Original file line number Diff line number Diff line change
1
+ let list = document . getElementById ( 'list' )
2
+ let n = document . getElementById ( 'n' )
3
+ let print = document . getElementById ( 'print' )
4
+
5
+ print . onclick = function ( ) {
6
+ let start = new Date ( ) . getTime ( )
7
+
8
+ for ( let i = 1 ; i <= n . value ; i ++ ) {
9
+ let x = ''
10
+ if ( i % 3 == 0 ) x += 'fizz'
11
+ if ( i % 5 == 0 ) x += 'buzz'
12
+ if ( x == '' ) x = i
13
+
14
+ list . innerHTML += `<li> ${ x } </li>`
15
+ }
16
+
17
+ let end = new Date ( ) . getTime ( )
18
+ console . log ( end - start )
19
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,21 @@ let list = document.getElementById('list')
2
2
let n = document . getElementById ( 'n' )
3
3
let print = document . getElementById ( 'print' )
4
4
5
- print . onclick = function ( ) {
5
+ print . onclick = function ( ) {
6
+ let start = new Date ( ) . getTime ( )
6
7
7
- }
8
+ let html = ''
9
+ for ( let i = 1 ; i <= n . value ; i ++ ) {
10
+ let x = ''
11
+ if ( i % 3 == 0 ) x += 'fizz'
12
+ if ( i % 5 == 0 ) x += 'buzz'
13
+ if ( x == '' ) x = i
14
+
15
+ html += `<li> ${ x } </li>`
16
+ }
8
17
18
+ list . innerHTML += html
19
+
20
+ let end = new Date ( ) . getTime ( )
21
+ console . log ( end - start )
22
+ }
You can’t perform that action at this time.
0 commit comments