File tree Expand file tree Collapse file tree 26 files changed +236
-244
lines changed
JavaScript DOM/Simple DOM Programs Expand file tree Collapse file tree 26 files changed +236
-244
lines changed Original file line number Diff line number Diff line change @@ -12,21 +12,7 @@ <h1 id="result" style="color: red;"></h1>
12
12
</ center >
13
13
14
14
< body >
15
- < script >
16
- const addTwo = ( num1 , num2 ) => {
17
- const sum = parseFloat ( num1 ) + parseFloat ( num2 ) ;
18
- return sum ;
19
-
20
- }
21
- document . getElementById ( 'sum' ) . addEventListener ( 'click' , ( ) => {
22
- const num1 = document . getElementById ( 'num1' ) . value ;
23
- const num2 = document . getElementById ( 'num2' ) . value ;
24
- const result = addTwo ( num1 , num2 ) ;
25
- if ( result ) {
26
- document . getElementById ( 'result' ) . innerText = 'Sum of two number is: ' + result . toFixed ( 3 ) ;
27
- }
28
- } )
29
- </ script >
15
+ < script src ="1.js "> </ script >
30
16
</ body >
31
17
32
18
</ html >
Original file line number Diff line number Diff line change
1
+ const addTwo = ( num1 , num2 ) => {
2
+ const sum = parseFloat ( num1 ) + parseFloat ( num2 ) ;
3
+ return sum ;
4
+
5
+ }
6
+ document . getElementById ( 'sum' ) . addEventListener ( 'click' , ( ) => {
7
+ const num1 = document . getElementById ( 'num1' ) . value ;
8
+ const num2 = document . getElementById ( 'num2' ) . value ;
9
+ const result = addTwo ( num1 , num2 ) ;
10
+ if ( result ) {
11
+ document . getElementById ( 'result' ) . innerText = 'Sum of two number is: ' + result . toFixed ( 3 ) ;
12
+ }
13
+ } )
Original file line number Diff line number Diff line change 4
4
< button id ="submit "> Submit</ button >
5
5
< h2 id ="result " style ="color: red; "> </ h2 >
6
6
7
- < script >
8
- document . getElementById ( 'submit' ) . addEventListener ( 'click' , ( ) => {
9
- const number = document . getElementById ( 'number' ) . value ;
10
- const result = document . getElementById ( 'result' ) ;
11
- if ( number === '' ) {
12
- result . innerText = 'Input filed is empty' ;
13
- }
14
- else if ( number >= 50 ) {
15
- result . innerText = 'You are allowed' ;
16
- }
17
-
18
- else if ( number < 50 ) {
19
- result . innerText = 'You are not allowed' ;
20
- }
21
- else {
22
- result . innerText = '' ;
23
- }
24
-
25
- } )
7
+ < script src ="10.js ">
26
8
</ script >
27
9
</ body >
28
10
</ html >
Original file line number Diff line number Diff line change
1
+ document . getElementById ( 'submit' ) . addEventListener ( 'click' , ( ) => {
2
+ const number = document . getElementById ( 'number' ) . value ;
3
+ const result = document . getElementById ( 'result' ) ;
4
+ if ( number === '' ) {
5
+ result . innerText = 'Input filed is empty' ;
6
+ }
7
+ else if ( number >= 50 ) {
8
+ result . innerText = 'You are allowed' ;
9
+ }
10
+
11
+ else if ( number < 50 ) {
12
+ result . innerText = 'You are not allowed' ;
13
+ }
14
+ else {
15
+ result . innerText = '' ;
16
+ }
17
+
18
+ } )
Original file line number Diff line number Diff line change 5
5
< input type ="text " id ="num2 ">
6
6
< button id ="btn "> Result</ button >
7
7
< div id ="result " style ="color: red; font-weight: bold; "> </ div >
8
- < script >
9
- document . getElementById ( 'btn' ) . addEventListener ( 'click' , ( ) => {
10
- document . getElementById ( 'result' ) . innerHTML = '' ;
11
- const num1 = document . getElementById ( 'num1' ) . value ;
12
- const num2 = document . getElementById ( 'num2' ) . value ;
13
- const num1Value = parseInt ( num1 ) ;
14
- const num2Value = parseInt ( num2 ) ;
15
-
16
- if ( num1Value > num2Value ) {
17
- alert ( 'Please give first number small and second number large' ) ;
18
- return ;
19
- }
20
- const div = document . getElementById ( 'result' ) ;
21
- for ( let i = num1Value ; i <= num2Value ; i ++ ) {
22
- const span = document . createElement ( 'span' ) ;
23
- span . innerText = `${ i } ` ;
24
- div . appendChild ( span ) ;
25
- }
26
- } )
27
-
8
+ < script src ="11.js ">
28
9
</ script >
29
10
</ body >
30
11
</ html >
Original file line number Diff line number Diff line change
1
+ document . getElementById ( 'btn' ) . addEventListener ( 'click' , ( ) => {
2
+ document . getElementById ( 'result' ) . innerHTML = '' ;
3
+ const num1 = document . getElementById ( 'num1' ) . value ;
4
+ const num2 = document . getElementById ( 'num2' ) . value ;
5
+ const num1Value = parseInt ( num1 ) ;
6
+ const num2Value = parseInt ( num2 ) ;
7
+
8
+ if ( num1Value > num2Value ) {
9
+ alert ( 'Please give first number small and second number large' ) ;
10
+ return ;
11
+ }
12
+ const div = document . getElementById ( 'result' ) ;
13
+ for ( let i = num1Value ; i <= num2Value ; i ++ ) {
14
+ const span = document . createElement ( 'span' ) ;
15
+ span . innerText = `${ i } ` ;
16
+ div . appendChild ( span ) ;
17
+ }
18
+ } )
Original file line number Diff line number Diff line change 2
2
< body >
3
3
< div id ="result " style ="color: red; font-size: 25px; font-weight: bold; "> </ div >
4
4
5
- < script >
6
- let num = 49 ;
7
- const div = document . getElementById ( 'result' ) ;
8
- while ( num >= 1 ) {
9
- const span = document . createElement ( 'span' ) ;
10
- span . innerText = `${ num } ` ;
11
- div . appendChild ( span ) ;
12
- num = num - 1 ;
13
- }
5
+ < script src ="12.js ">
14
6
</ script >
15
7
</ body >
16
8
</ html >
Original file line number Diff line number Diff line change
1
+ let num = 49 ;
2
+ const div = document . getElementById ( 'result' ) ;
3
+ while ( num >= 1 ) {
4
+ const span = document . createElement ( 'span' ) ;
5
+ span . innerText = `${ num } ` ;
6
+ div . appendChild ( span ) ;
7
+ num = num - 1 ;
8
+ }
Original file line number Diff line number Diff line change 4
4
5
5
< h2 id ="array "> </ h2 >
6
6
< h1 id ="result "> </ h1 >
7
- < script >
8
- const ob = [ ] ;
9
- ob [ 0 ] = 6 ;
10
- ob [ 1 ] = 11 ;
11
- ob [ 2 ] = 2 ;
12
- ob [ 3 ] = 0 ;
13
- ob [ 4 ] = 1 ;
14
- ob [ 5 ] = 6 ;
15
- ob [ 6 ] = 16 ;
16
- ob [ 7 ] = 6 ;
17
- ob [ 8 ] = 6 ;
18
- ob [ 9 ] = 3 ;
19
-
20
- let sum = 0 ;
21
- for ( let i = 0 ; i < ob . length ; i ++ ) {
22
- const num = ob [ i ] ;
23
- sum += num ;
24
- }
25
- document . getElementById ( 'array' ) . innerText = `Array contains: ${ ob } `
26
-
27
- const avg = sum / ob . length ;
28
- document . getElementById ( 'result' ) . innerText = `Average value of the array is: ${ avg } ` ;
29
-
7
+ < script src ="13.js ">
30
8
</ script >
31
9
</ body >
32
10
Original file line number Diff line number Diff line change
1
+ const ob = [ ] ;
2
+ ob [ 0 ] = 6 ;
3
+ ob [ 1 ] = 11 ;
4
+ ob [ 2 ] = 2 ;
5
+ ob [ 3 ] = 0 ;
6
+ ob [ 4 ] = 1 ;
7
+ ob [ 5 ] = 6 ;
8
+ ob [ 6 ] = 16 ;
9
+ ob [ 7 ] = 6 ;
10
+ ob [ 8 ] = 6 ;
11
+ ob [ 9 ] = 3 ;
12
+
13
+ let sum = 0 ;
14
+ for ( let i = 0 ; i < ob . length ; i ++ ) {
15
+ const num = ob [ i ] ;
16
+ sum += num ;
17
+ }
18
+ document . getElementById ( 'array' ) . innerText = `Array contains: ${ ob } `
19
+
20
+ const avg = sum / ob . length ;
21
+ document . getElementById ( 'result' ) . innerText = `Average value of the array is: ${ avg } ` ;
You can’t perform that action at this time.
0 commit comments