Rock Paper Scissor Game Using Javascript

<script>

    function random(){

      var item = ["Rock","Paper","Sessior"];

     var rand =  item[Math.floor(Math.random()*item.length)];

     return rand;

 

    }

 

    function r(){

        var rock = document.getElementById("r").value;

        var computerinput = random();

       

        if(rock=="Rock" && computerinput=="Rock")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Match Tie</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+rock+"</b>";

           

        }

        else if(rock=="Rock" && computerinput=="Paper")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Computer Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+rock+"</b>";

        }

        else if(rock=="Rock" && computerinput=="Sessior")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>User Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+rock+"</b>";

        }

 

    }



 

    function p(){

       

        var paper = document.getElementById("p").value;

        var computerinput = random();

       

        if(paper=="Paper" && computerinput=="Rock")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Computer Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+paper+"</b>";

           

        }

        else if(paper=="Paper" && computerinput=="Paper")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Match Tie!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+paper+"</b>";

        }

        else if(paper=="Paper" && computerinput=="Sessior")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Computer Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+paper+"</b>";

        }

 

    }


 

    function s(){

       

        var sessior = document.getElementById("s").value;

        var computerinput = random();

       

        if(sessior=="Sessior" && computerinput=="Rock")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>COmputer Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+sessior+"</b>";

           

        }

        else if(sessior=="Sessior" && computerinput=="Paper")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>User Win!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+sessior+"</b>";

        }

        else if(sessior=="Sessior" && computerinput=="Sessior")

        {

            document.getElementById("result").innerHTML="<b style='color:steelblue'>Match Tie!</b>"+"Computer Input is <b style='color:red;'>"+computerinput+"</b> User Input is <b style='color:green;'>"+sessior+"</b>";

        }

 

    }

</script>


 

<center>

<input type="button" id="r" onclick="r()" value="Rock">

<input type="button" id="p" onclick="p()" value="Paper">

<input type="button" id="s" onclick="s()" value="Scissor">

 

<br>

<br>

<div id="result"></div>

</center>

 



Explore Our YouTube Tutorials

Dive into our YouTube tutorials to access high-quality learning content on web development, design, and technology. Each video is crafted to provide clear guidance and hands-on knowledge for skill development.

 


Upgrade Your Skills with Our Courses

Choose the right course and start building your future with practical skills.

Web Development

Learn HTML, CSS, JavaScript, and PHP to build modern, responsive websites and real-world projects.

Enroll Now See Full Details

Breadboard Learning

Understand electronics basics with hands-on breadboard projects and circuit building techniques.

Enroll Now See Full Details

AI Training

Step into AI with real-world applications, automation tools, and smart development techniques.

Enroll Now See Full Details