1+ const button = document . querySelector ( 'button' ) ;
2+ const body = document . querySelector ( '#body' ) ;
3+ const div = document . querySelector ( "div.button1" )
4+ let reset
5+ const rMerah = document . querySelector ( 'input[name="rMerah"]' )
6+ const rHijau = document . querySelector ( 'input[name="rHijau"]' )
7+ const rBiru = document . querySelector ( 'input[name="rBiru"]' )
8+
9+ button . addEventListener ( 'click' , function ( ) {
10+ document . body . style . backgroundColor = 'red'
11+ button . remove ( )
12+ const random = document . createElement ( 'button' ) ;
13+ const tRandom = document . createTextNode ( 'Acak Warna' )
14+
15+ random . appendChild ( tRandom )
16+ div . appendChild ( random )
17+
18+ random . addEventListener ( 'click' , function ( ) {
19+ let r = Math . round ( Math . random ( ) * 255 + 1 )
20+ let g = Math . round ( Math . random ( ) * 255 + 1 )
21+ let b = Math . round ( Math . random ( ) * 255 + 1 )
22+ document . body . style . backgroundColor = 'rgb(' + r + ', ' + g + ', ' + b + ')'
23+ if ( ! reset ) {
24+ console . log ( reset )
25+ reset = document . createElement ( 'button' ) ;
26+ tReset = document . createTextNode ( 'reset' )
27+ reset . appendChild ( tReset )
28+ reset . setAttribute ( 'type' , 'reset' )
29+ div . appendChild ( reset )
30+ reset . addEventListener ( 'click' , function ( ) {
31+ window . location . reload ( )
32+ } )
33+ }
34+
35+ } )
36+ } )
37+
38+ rMerah . addEventListener ( 'change' , function ( ) {
39+ document . body . style . backgroundColor = 'rgb(' + rMerah . value + ',' + rHijau . value + ',' + rBiru . value + ')'
40+ } )
41+
42+ rHijau . addEventListener ( 'change' , function ( ) {
43+ document . body . style . backgroundColor = 'rgb(' + rMerah . value + ',' + rHijau . value + ',' + rBiru . value + ')'
44+ } )
45+
46+ rBiru . addEventListener ( 'change' , function ( ) {
47+ document . body . style . backgroundColor = 'rgb(' + rMerah . value + ',' + rHijau . value + ',' + rBiru . value + ')'
48+ } )
49+
50+ window . addEventListener ( "mousemove" , function ( e ) {
51+ const xPos = e . clientX
52+ const yPos = e . clientY
53+ const windowWidth = window . innerWidth
54+ const windowHeight = window . innerHeight
55+ // console.log(xPos)
56+
57+ const redXPos = Math . round ( ( xPos / windowWidth ) * 255 ) ;
58+ const greenXPos = Math . round ( ( yPos / windowHeight ) * 255 ) ;
59+
60+ document . body . style . backgroundColor = 'rgb(' + redXPos + ',' + greenXPos + ',0)'
61+ } )
0 commit comments