guessing game


 

<html>

<head>

<style>

.myDiv {

  border: 5px outset red;

  background-color: black;    

  text-align: center;

}

</style>

</head>

<body>

  

<div class="myDiv">

  <h2>Guessing Game</h2>

</div>

<h2> Enter your 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);

                         

                switch(Number(n))

                 {

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

                    document.getElementById("display").innerHTML="dark salmon"; 

               

                     break

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

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

                  

                     break;

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

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

                   

                    break

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

                       

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

                   

                     break;

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

                       c="orange";

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

                     break;

                     

                     break

                    case 5:document.getElementById("display").style.background="Yellow";

                       

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

                   

                     break;

 

                 

                 }


if(x==n)

        {

               document.getElementById("display2").style.color="yellow";

               document.getElementById("display2").style.background="black";

               document.getElementById("display2").innerHTML="Congratulations , You  Guess it Right "; 

               

               

         }

                        else

           {

                          document.getElementById("display2").style.background="red";

                          document.getElementById("display2").innerHTML="Im sorry you are wrong, the Correct Answer is " +x; 

                                               

               

        }

        

}


</script>

</body>

</html>

Comments

Popular posts from this blog