JAVASCRIPT GUESS A NUMBER

 <!DOCTYPE html>

<html>

<body>


<h2>Enter A Guess Number </h2>

<input type="text"id="input1" onkeydown="keydownevent()"/>


<p id="display">

<p id="display2">


<script>

<!--


 function keydownevent()

 {

         document.getElementById("input1");

         n=document.getElementById("input1").value; 

          document.getElementById("display").style.color="white";

          x=Math.floor(Math.random()*5+1);

          var c;

          switch(Number(n))

          {

           case 1: document.getElementById("display").style.background="pink";

                   document.getElementById("display").innerHTML="pink";

                                                        

           break

           

           case 2: document.getElementById("display").style.background="blue";

                   document.getElementById("display").innerHTML="blue";

                   

                   break;

                   

          case 3: document.getElementById("display").style.background="maroon";

                   document.getElementById("display").innerHTML="maroon";

                   

                   break

                   

         case 4: document.getElementById("display").style.background="green";

                   document.getElementById("display").innerHTML="green";

                           

                  break;

                  

       default: case 4: document.getElementById("display").style.background="orange";

       c="orange";

         document.getElementById("display").innerHTML="orange";

            break;

            

            }

            

            if(x==n)

            {

   document.getElementById("display2").innerHTML="Congratulations, You guess it right ";

   

   }

   

    else

    

    {

    

   document.getElementById("display2").innerHTML="I'm sorry you are wrong, The correct answer is " +x;

   

   }

   

   }

   //->

   

   </script>

   </body>

   </html>

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

                 

Comments

Popular Posts