1+ var theNum = 0 ;
2+ var counter = 0 ;
3+ function randomNum ( ) {
4+ theNum = Math . floor ( ( Math . random ( ) * 100 ) + 1 ) ;
5+ console . log ( theNum ) ;
6+ }
7+
8+ var input = document . getElementById ( "numInput" ) ;
9+ input . addEventListener ( "keyup" , function ( event ) {
10+ if ( event . keyCode === 13 ) {
11+ event . preventDefault ( ) ;
12+ document . getElementById ( "guessButton" ) . click ( ) ;
13+ }
14+ } ) ;
15+
16+ function guessNum ( ) {
17+ counter ++ ;
18+ document . getElementById ( "counter" ) . innerHTML = counter ;
19+ var numIn = 0 ;
20+ numIn = document . getElementById ( "numInput" ) . value ;
21+ console . log ( numIn ) ;
22+ if ( numIn > theNum ) {
23+ console . log ( "high" ) ;
24+ document . getElementById ( "theIcon" ) . className = "fas fa-arrow-down" ;
25+ document . body . style . backgroundColor = "red" ;
26+ //document.body.style.backgroundImage = "linear-gradient(-90deg, red " + theNum + "%, green)";
27+ //document.body.style.backgroundImage = "linear-gradient(-90deg, red, green " + (100 * numIn) / theNum + "%)";
28+ //document.body.style.background = "linear-gradient(to right, rgba(0, 255, 0, 1) " + (((100 * numIn) / theNum)) + "%, rgba(255, 0, 0, 1) 100%)";
29+ //document.getElementById("mainContainer").style.background = "linear-gradient(90deg, rgba(0,255,16,1)" + (((100 * numIn) / theNum)) + "%, rgba(0,0,0,0) 100%)";
30+ console . log ( ( ( ( 100 * numIn ) / theNum ) - 10 ) ) ;
31+ }
32+ else if ( numIn < theNum ) {
33+ console . log ( "low" ) ;
34+ document . getElementById ( "theIcon" ) . className = "fas fa-arrow-up" ;
35+ document . body . style . backgroundColor = "red" ;
36+ //document.body.style.backgroundImage = "linear-gradient(-90deg, red, green " + (100 * theNum) / numIn + "%)";
37+ //document.body.style.background = "linear-gradient(to right, rgba(0, 255, 0, 1) " + (((100 * numIn) / theNum)) + "%, rgba(255, 0, 0, 1) 100%)";
38+ //document.getElementById("mainContainer").style.background = "linear-gradient(90deg, rgba(0,255,16,1)" + (((100 * numIn) / theNum)) + "%, rgba(0,0,0,0) 100%)";
39+ console . log ( ( ( ( 100 * theNum ) / numIn ) - 10 ) ) ;
40+ }
41+ else if ( numIn == theNum ) {
42+ console . log ( "match" ) ;
43+ document . getElementById ( "theIcon" ) . className = "fas fa-check-circle" ;
44+ document . getElementById ( "theGuessing" ) . style . display = "none" ;
45+ document . getElementById ( "correctNum" ) . innerHTML = theNum ;
46+ document . getElementById ( "congo" ) . style . display = "block" ;
47+ document . body . style . backgroundColor = "limegreen" ;
48+ }
49+ document . getElementById ( "numInput" ) . value = '' ;
50+ }
0 commit comments