File tree Expand file tree Collapse file tree 4 files changed +58
-3
lines changed Expand file tree Collapse file tree 4 files changed +58
-3
lines changed Original file line number Diff line number Diff line change 55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
66 < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
77 < title > Document</ title >
8- < script defer src ="script.js "> </ script >
8+ < script defer src ="script-createelement .js "> </ script >
99</ head >
1010< body >
1111
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')
22let n = document . getElementById ( 'n' )
33let print = document . getElementById ( 'print' )
44
5- print . onclick = function ( ) {
5+ print . onclick = function ( ) {
6+ let start = new Date ( ) . getTime ( )
67
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+ }
817
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