You are currently viewing Rock Paper Scissors Game using HTML, CSS & JavaScript

Rock Paper Scissors Game using HTML, CSS & JavaScript

Free Coding Ebook 👉 Get Now

Rock Paper Scissors Game using HTML, CSS & JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. Today we’ll learn how to make a game which we have played in our childhood Rock Paper Scissors to make it possible, In Today’s Project we will use HTML, CSS, and JavaScript to complete this Project.

The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements. And contributes the most while creating a structure for the Rock Paper Scissors Project.

Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment.


At last we will use JS (JavaScript) which will add a logic to make the project responsive from the user end.

I hope you have got an idea about the project.

HTML Code for Rock Paper Scissor

<html lang="en">
    <title>Rock Paper Scissor Game</title>
    <link rel="stylesheet" href="">
    <!--Google Font-->
    <link rel="preconnect" href="">
    <link href=";600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
    <div class="container">
        <div class="scores">
            <p>Computer : 
                <span id="computer_score">0</span>
                You :
                <span id="user_score">0</span>
        <div class="weapons">
            <button onclick="checker('rock')">
                <i class="far fa-hand-rock"></i>
            <button onclick="checker('paper')">
                <i class="far fa-hand-paper"></i>
            <button onclick="checker('scissor')">
                <i class="far fa-hand-scissors"></i>
        <div class="details">
            <p id="user_choice"></p>
            <p id="comp_choice"></p>
            <p id="result"></p>

    <script src="script.js"></script>

First we’ll start with creating the structure of the Rock Paper & Scissors project for that as you can see the above code we have used all the necessary elements & attributes. Let us know code the CSS part to add styling and aligned the tags used to create the project.

Create Simple Portfolio Website Using Html Css (Portfolio Website Source Code)

CSS Code for Rock Paper Scissor

    padding: 0;
    margin: 0;
    box-sizing: border-box;
    height: 100vh;
    background: linear-gradient(
    width: 45%;
    min-width: 500px;
    background-color: #ffffff;
    padding: 40px 30px;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 10px;
    box-shadow: 0 15px 25px rgba(0,0,0,0.15);
    margin-bottom: 50px;
    text-align: right;
    width: 90%;
    margin: auto;
    display: flex;
    justify-content: space-around;
.weapons button{
    background-color: #ffd51b;
    color: #000000;
    border: none;
    font-size: 50px;
    height: 100px;
    width: 100px;
    border-radius: 50%;
    outline: none;
    cursor: pointer;
    margin-top: 30px;
    text-align: center;
    font-family: 'Poppins',sans-serif;
    font-weight: 400;
    font-size: 15px;
    width: 180px;
    padding: 10px 0;
    margin: 30px auto;
    font-weight: 600;
    letter-spacing: 0.5px;
    font-weight: 400;
    margin-bottom: 10px;
    font-weight: 600;

Second, comes the CSS code which we have styled for the structure we have padded as well as aligned the project so that it is properly situated and doesn’t get messy with suitable CSS elements for Rock Paper Scissors Project. Now, let’s code the JavaScript part to make it responsive.

50+ Html ,Css &#038; Javascript Projects With Source Code

JavaScript Code for Rock Paper Scissor

let [computer_score,user_score]=[0,0];
let result_ref = document.getElementById("result");
let choices_object = {
    'rock' : {
        'rock' : 'draw',
        'scissor' : 'win',
        'paper' : 'lose'
    'scissor' : {
        'rock' : 'lose',
        'scissor' : 'draw',
        'paper' : 'win'
    'paper' : {
        'rock' : 'win',
        'scissor' : 'lose',
        'paper' : 'draw'


function checker(input){
    var choices = ["rock", "paper", "scissor"];
    var num = Math.floor(Math.random()*3);

    document.getElementById("comp_choice").innerHTML = 
    ` Computer choose <span> ${choices[num].toUpperCase()} </span>`;

    document.getElementById("user_choice").innerHTML = 
    ` You choose <span> ${input.toUpperCase()} </span>`;

    let computer_choice = choices[num];

        case 'win':
   = "background-color: #cefdce; color: #689f38";
            result_ref.innerHTML = "YOU WIN";
        case 'lose':
   = "background-color: #ffdde0; color: #d32f2f";
            result_ref.innerHTML = "YOU LOSE";
   = "background-color: #e5e5e5; color: #808080";
            result_ref.innerHTML = "DRAW";

    document.getElementById("computer_score").innerHTML = computer_score;
    document.getElementById("user_score").innerHTML = user_score;

Last stage of the project the JavaScript which we added the logic and coded as per the requirement with some conditions. And defined some conditions when to declare a winner in each scenario when it is clicked on Rock, Paper & Scissors. Let us see the Final Output of the project Rock Paper Scissors using HTML, CSS & JavaScript (Source Code) | Rock Paper Scissor.

100+ JavaScript Projects With Source Code ( Beginners to Advanced)

Final Output Rock Paper Scissors Game using HTML, CSS & JavaScript

We have Successfully created our Rock Paper Scissors Game using HTML, CSS & JavaScript (Source Code). You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

If you find out this Blog helpful, then make sure to search code with random on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

Free Coding Ebook 👉 Get Now

Leave a Reply