File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-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
+ < title > Javascript BOM Practice</ title >
6
+ </ head >
7
+ < body >
8
+ < input type ="text " placeholder ="Enter a Key " id ="enteredKey ">
9
+ < br >
10
+ < input type ='button ' value ="Click on Me " id ="clicked ">
11
+ < br >
12
+ < input type ="button " value ="Start Clock " id ="Clock ">
13
+ < br >
14
+ < div id ="current-clock " style ="text-align: center; font-weight: bold; "> </ div >
15
+ < script src ="main.js "> </ script >
16
+ </ body >
17
+ </ html >
Original file line number Diff line number Diff line change
1
+ ( function userInput ( ) {
2
+ let input = window . document . getElementById ( 'enteredKey' )
3
+ input . addEventListener ( 'keydown' , ( e ) => {
4
+ alert ( 'You Pressed: ' + e . key )
5
+ } ) ;
6
+ } ( ) ) ;
7
+
8
+
9
+ ( function userClicked ( ) {
10
+ let clicked = window . document . getElementById ( 'clicked' )
11
+ clicked . addEventListener ( 'click' , ( event ) => {
12
+ if ( event . button === 0 ) { // 0 = left click
13
+ alert ( 'You Clicked Left Mouse Button' )
14
+ } else if ( event . button === 2 ) { // 2 = right click
15
+ alert ( 'You Clicked Right Mouse Button' )
16
+ } else { // 1 = middle click
17
+ alert ( 'You Clicked Middle Mouse Button' )
18
+ }
19
+ } )
20
+ } ( ) ) ;
21
+
22
+
23
+ window . document . addEventListener ( 'keydown' , ( e ) => {
24
+ if ( e . altKey && e . key === 'w' ) {
25
+ alert ( 'clock stopped..' )
26
+ clearInterval ( window )
27
+ }
28
+ } )
29
+
30
+ window . document . getElementById ( 'Clock' ) . onclick = ( ) => {
31
+ alert ( 'Clock Started ...' )
32
+ var currClock = window . document . getElementById ( 'current-clock' )
33
+ currClock . innerHTML = new Date ( ) . toLocaleTimeString ( )
34
+
35
+ setInterval ( ( ) => {
36
+ currClock . innerHTML = new Date ( ) . toLocaleTimeString ( )
37
+ } , 1000 )
38
+ } ;
You can’t perform that action at this time.
0 commit comments