Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

    <h2>Make Your Move</h2>
    <div class="container">
        <div id="r" class="userChoices">
            <img src="https://image.flaticon.com/icons/svg/3094/3094121.svg"/>
        </div>
        <div id="p" class="userChoices">
            <img src="https://image.flaticon.com/icons/svg/3094/3094132.svg"/>
        </div>
        <div id="s" class="userChoices">
            <img src="https://image.flaticon.com/icons/svg/2919/2919560.svg"/>
        </div>
        <div class="keys">
            <p>ROCK</p>            
        </div>
        <div class="keys">
            <p>PAPER</p>
        </div>
        <div class="keys">
            <p>SCISSORS</p>
        </div>

        <h2>The Computers Choice</h2>

        <div class="computerChoiceContainer">
            <div class="computerChoice">
                <p><img src="https://image.flaticon.com/icons/svg/2910/2910897.svg"></p>
            </div>
        </div>
        
        <div class="result">
            <p>Result:</p>
            <button onclick=onclick="location.reload();" class="reset">Reset Game</button>
        </div>
    </div>

    <script src="script.js"></script>
    
</body>
</html>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Sedgwick+Ave+Display&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Shadows+Into+Light&display=swap');

* {
    box-sizing: border-box;
  }

body {
    background-color: #CCC9E7;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #2E3138;
    font-family: 'Shadows Into Light', cursive;
}

h2 {
    line-height: 10px;
    margin-top: 0px;
    margin-bottom: -30px;
}

.container {
    width: 600px;
    height: 100vh;
    margin: auto;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-evenly;
    align-items: center;
    text-align: center;
}

.userChoices {
    width: 140px;
    height: 140px;
    border: solid 2px #2E3138;
    border-radius: 4px;
    margin: 10px;
    margin-bottom: -30px;
}

.userChoices:hover {
    transform: scale(1.1);
    cursor: pointer;
}

.userChoices img {
    width: 120px;
    opacity: 70%;
    margin-top: 10px;
}

.keys {
    background: #2E3138;
    color: #CCC9E7;
    margin: 10px;
    width: 140px;
    height: 50px;
    border-radius: 4px;
    margin-top: -30px;
    margin-bottom: -30px;
}

.keys p {
    margin-top: 12px;
}

.computerChoiceContainer {
    width: 100%;
    height: 150px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: -50px;
    margin-bottom: -30px;
}

.computerChoice {
    width: 140px;
    height: 140px;
    border: solid 2px #2E3138;
    border-radius: 4px;
}

.computerChoice img {
    width: 100px;
    opacity: 70%;
    margin-top: 10px;
}


.result {
    width: 100%;
    height: 70px;
    font-size: 30px;
    margin-top: -75px;
    font-family: 'Shadows Into Light', cursive;
}

.reset {
    background: #2E3138;
    color: #CCC9E7;
    width: 150px;
    height: 35px;
    border-radius: 4px;
    font-family: 'Shadows Into Light', cursive;
    font-size: 18px;
    border: none;
    margin-top: -15px;
}
              
            
!

JS

              
                const rockDiv = document.getElementById("r");
const paperDiv = document.getElementById("p");
const scissorDiv = document.getElementById("s");
const resultp = document.querySelector(".result > p");
const computerChoiceP = document.querySelector(".computerChoice > p");
const resetGame = document.getElementById("reset");

//use math random to generate a computer choice
function getComputerChoice() {
    const computerChoices = ['r','p','s']
    const randomNumber = Math.floor(Math.random() * 3);
    return computerChoices[randomNumber];
}

//function to display image relevant to computer choice
function displayComputerChoice(computerChoice) {
    if (computerChoice ==='r') {
        computerChoiceP.innerHTML= "<img src=\"https://image.flaticon.com/icons/svg/3094/3094121.svg\">";
    } else if (computerChoice === 'p') {
        computerChoiceP.innerHTML = "<img src=\"https://image.flaticon.com/icons/svg/3094/3094132.svg\">";;
    } else if (computerChoice === 's') {
        computerChoiceP.innerHTML = "<img src=\"https://image.flaticon.com/icons/svg/2919/2919560.svg\">";
    }
}

//functions to diplay results
function win() {
    resultp.innerHTML = 'Result: YOU WIN!'
}

function lose() {
    resultp.innerHTML = 'Result: YOU LOSE!'
}

function draw() {
    resultp.innerHTML = 'Result: IT\'S A DRAW'
}

//function to determine result - comparing user & comp choices
function game (userChoice) {
    const computerChoice = getComputerChoice();
    switch (userChoice + computerChoice){
        case 'rs':
        case 'pr':
        case 'sp':
            win();
            break;
        case 'rp':
        case 'ps':
        case 'sr':
            lose();
            break;
        case 'rr':
        case 'pp':
        case 'ss':
            draw();
            break;
    }
    (displayComputerChoice(computerChoice))
}

//event listeners
function main () {
rockDiv.addEventListener('click', function() {
    game("r")
    document.getElementById("r").style.borderColor="#eb4034";
})

paperDiv.addEventListener('click', function() {
    game("p")
    document.getElementById("p").style.borderColor="#eb4034";
})

scissorDiv.addEventListener('click', function() {
    game("s")
    document.getElementById("s").style.borderColor="#eb4034";
})
}

main ();

function refreshPage() {
  // window.location.href = window.location.href;
  location.reload();
}
              
            
!
999px

Console