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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                    <main> 
      <section>
        <h1> <span></span></h1>
        <div class="scoreboard-container">
          <div class="scoreboard-title"> 
            <h2>Scoreboard</h2>
          </div>
          <div class="scoreboard-results">
            <div class="scoreboard-user badge" id="user-badge"><span id="user-score">0</span>
              <p>User </p>
            </div>
            <div class="scoreboard-cpu badge" id="cpu-badge"> <span id="cpu-score">0</span>
              <p>CPU</p>
            </div>
          </div>
          <div class="button-container">
            <button id="restart-game">Restart</button>
          </div>
        </div>
        <div class="result-popup">
          <div class="result-popup-container"><img class="close-icon" src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/close.svg" alt="close"><img class="result-image" src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/win.svg" alt="win">
            <h2 class="result-display"></h2>
            <div class="result-choices">
              <div class="result-choices-user"><img class="user-choice-image" src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/rock.svg" alt="user-choice">
                <h4 class="user-choice"></h4>
                <h4 class="player">USER</h4>
              </div>
              <h3 class="results-action">VS</h3>
              <div class="result-choices-cpu"><img class="cpu-choice-image" src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/scissors.svg" alt="cpu-choice">
                <h4 class="cpu-choice"> </h4>
                <h4 class="player">CPU</h4>
              </div>
            </div>
          </div>
        </div>
        <div class="user-choice--container">
          <h3>Make your choice!</h3>
          <div class="user-choice-buttons"> 
            <div class="button" id="rock"><img src="
							https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/rock.svg">
              <p>rock</p>
            </div>
            <div class="button" id="scissors"><img src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/scissors.svg">
              <p>scissors</p>
            </div>
            <div class="button" id="paper"><img src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/paper.svg">
              <p>paper</p>
            </div>
            <div class="button" id="lizard"><img src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/lizard.svg">
              <p>lizard</p>
            </div>
            <div class="button" id="spock"><img src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/spock.svg">
              <p>spock</p>
            </div>
          </div>
        </div>
        <div class="help"> <span>?</span></div>
        <div class="instructions-popup">
          <div class="instructions-popup-container"><img src="https://content.instructables.com/ORIG/FIU/AIWE/I7Q0TCUT/FIUAIWEI7Q0TCUT.jpg?auto=webp&amp;frame=1&amp;fit=bounds&amp;md=5b8102e911f24990417073b8517e53d2"><img class="close-icon close-instructions" src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/close.svg" alt="close"></div>
        </div>
      </section>
    </main>
              
            
!

CSS

              
                @charset "UTF-8";
/*
    1. Position: fixed, relative, absolute
    2. Box Model: margin, padding, width
    3. Fonts: fuentes, tamaños, colores
    4. Visuals: shadow box, border radius
    5. Others
*/
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 62.5%;
  font-family: "Roboto", sans-serif;
}

/*
  Reset button styles
  It takes a little bit of work to achieve a “blank slate” look.
*/
button {
  padding: 0;
  border: none;
  font: inherit;
  color: inherit;
  background-color: transparent;
  /*
    Show a hand cursor on hover instead of the default arrow cursor
    (Some argue that we should keep the default arrow cursor for buttons, to be consistent with how desktop operating systems treat buttons.)
  */
  cursor: pointer;
}

main {
  width: 100%;
  min-height: 100vh;
  background: url(https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/bg_game.jpg);
  background-size: cover;
  background-position: center center;
  display: grid;
  position: relative;
}
main section {
  width: 90%;
  margin: auto;
  padding: 50px;
  background-color: white;
  border-radius: 32px;
  min-height: 90vh;
  display: flex;
  flex-direction: column;
  /* align-items: center; */
  justify-content: space-between;
}
main section h1 {
  font-size: 5.5rem;
  color: #e14759;
  text-transform: uppercase;
  text-align: center;
}
main section h1 span:before {
  content: "Rock";
  -webkit-animation: animate infinite 5s;
          animation: animate infinite 5s;
}
@-webkit-keyframes animate {
  0% {
    content: "Rock";
  }
  20% {
    content: "Scissors";
  }
  40% {
    content: "Paper";
  }
  60% {
    content: "Lizard";
  }
  80% {
    content: "Spock";
  }
}
@keyframes animate {
  0% {
    content: "Rock";
  }
  20% {
    content: "Scissors";
  }
  40% {
    content: "Paper";
  }
  60% {
    content: "Lizard";
  }
  80% {
    content: "Spock";
  }
}
main section .scoreboard-container {
  width: 100%;
  margin: 20px auto;
}
@media (min-width: 768px) {
  main section .scoreboard-container {
    width: 70%;
    max-width: 80%;
  }
}
main section .scoreboard-container .scoreboard-title {
  height: 50px;
  background: linear-gradient(60deg, #081d27, #1d2d47);
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 16px 16px 0 0;
}
main section .scoreboard-container .scoreboard-title h2 {
  font-size: 3rem;
  line-height: 3.6rem;
  letter-spacing: 5px;
  color: #fff;
  text-align: center;
  text-transform: uppercase;
}
main section .scoreboard-container .button-container {
  display: flex;
  margin: 20px auto;
  justify-content: center;
}
main section .scoreboard-container .button-container button {
  font-size: 1.4rem;
  text-transform: uppercase;
  font-weight: 500;
  letter-spacing: 1px;
  background: #e14759;
  color: white;
  width: 100px;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 1px 3px 0 #00000070;
}
@media (min-width: 768px) {
  main section .scoreboard-container .button-container button {
    font-size: 1.6rem;
  }
}
main section .scoreboard-container .button-container button:hover {
  transform: scale(1.1);
}
main section .scoreboard-results {
  width: 100%;
  display: inline-flex;
}
main section .scoreboard-results .badge {
  width: 50%;
  text-align: center;
  color: #fff;
  font-weight: bold;
  padding: 10px;
}
main section .scoreboard-results .badge span {
  font-size: 4.5rem;
}
main section .scoreboard-results .badge p {
  font-size: 1.8rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin-top: 10px;
}
main section .scoreboard-results .scoreboard-user {
  background-color: #53b7c7;
  border-radius: 0 0 0 16px;
}
main section .scoreboard-results .scoreboard-cpu {
  background-color: #cd7a2e;
  border-radius: 0 0 16px 0;
}
main .result-popup, main .instructions-popup {
  visibility: hidden;
  width: 100%;
  height: 100%;
  background-color: #081d27d3;
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
}
main .result-popup .result-popup-container, main .result-popup .instructions-popup-container, main .instructions-popup .result-popup-container, main .instructions-popup .instructions-popup-container {
  width: 80%;
  height: auto;
  max-height: 80vh;
  background-color: #fff;
  border-radius: 16px;
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 30px 0;
  position: relative;
}
@media (min-width: 768px) {
  main .result-popup .result-popup-container, main .result-popup .instructions-popup-container, main .instructions-popup .result-popup-container, main .instructions-popup .instructions-popup-container {
    width: 50%;
  }
}
main .result-popup .result-popup-container .close-icon, main .result-popup .instructions-popup-container .close-icon, main .instructions-popup .result-popup-container .close-icon, main .instructions-popup .instructions-popup-container .close-icon {
  position: absolute;
  width: 20px;
  right: 20px;
  top: 20px;
  right: 20px;
}
main .result-popup .result-popup-container .close-icon:hover, main .result-popup .instructions-popup-container .close-icon:hover, main .instructions-popup .result-popup-container .close-icon:hover, main .instructions-popup .instructions-popup-container .close-icon:hover {
  cursor: pointer;
}
main .result-popup .result-popup-container .result-image, main .result-popup .instructions-popup-container .result-image, main .instructions-popup .result-popup-container .result-image, main .instructions-popup .instructions-popup-container .result-image {
  width: 250px;
  height: auto;
  margin-bottom: 20px;
}
main .result-popup .result-popup-container h2.result-display, main .result-popup .instructions-popup-container h2.result-display, main .instructions-popup .result-popup-container h2.result-display, main .instructions-popup .instructions-popup-container h2.result-display {
  color: #53b7c7;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 1.6rem;
}
main .result-popup .result-popup-container .result-choices, main .result-popup .instructions-popup-container .result-choices, main .instructions-popup .result-popup-container .result-choices, main .instructions-popup .instructions-popup-container .result-choices {
  display: flex;
  width: 60%;
  margin: 20px auto;
  justify-content: space-between;
  align-items: flex-end;
  text-align: center;
}
main .result-popup .result-popup-container .result-choices img, main .result-popup .instructions-popup-container .result-choices img, main .instructions-popup .result-popup-container .result-choices img, main .instructions-popup .instructions-popup-container .result-choices img {
  width: 80px;
  height: auto;
  margin-bottom: 10px;
}
main .result-popup .result-popup-container .result-choices h3, main .result-popup .result-popup-container .result-choices h4, main .result-popup .instructions-popup-container .result-choices h3, main .result-popup .instructions-popup-container .result-choices h4, main .instructions-popup .result-popup-container .result-choices h3, main .instructions-popup .result-popup-container .result-choices h4, main .instructions-popup .instructions-popup-container .result-choices h3, main .instructions-popup .instructions-popup-container .result-choices h4 {
  text-transform: uppercase;
  letter-spacing: 1px;
}
main .result-popup .result-popup-container .result-choices h3, main .result-popup .instructions-popup-container .result-choices h3, main .instructions-popup .result-popup-container .result-choices h3, main .instructions-popup .instructions-popup-container .result-choices h3 {
  font-size: 3.2rem;
  align-self: center;
}
main .result-popup .result-popup-container .result-choices h4, main .result-popup .instructions-popup-container .result-choices h4, main .instructions-popup .result-popup-container .result-choices h4, main .instructions-popup .instructions-popup-container .result-choices h4 {
  font-size: 1.5rem;
}
main .result-popup .result-popup-container .result-choices .player, main .result-popup .instructions-popup-container .result-choices .player, main .instructions-popup .result-popup-container .result-choices .player, main .instructions-popup .instructions-popup-container .result-choices .player {
  font-style: italic;
  font-size: 1.1rem;
  color: lightgray;
}
main .result-popup .result-popup-container .result-choices-user img, main .result-popup .instructions-popup-container .result-choices-user img, main .instructions-popup .result-popup-container .result-choices-user img, main .instructions-popup .instructions-popup-container .result-choices-user img {
  filter: hue-rotate(145deg);
}
main .result-popup .result-popup-container .result-choices-cpu img, main .result-popup .instructions-popup-container .result-choices-cpu img, main .instructions-popup .result-popup-container .result-choices-cpu img, main .instructions-popup .instructions-popup-container .result-choices-cpu img {
  filter: hue-rotate(290deg);
  transform: scaleX(-1);
}
main .user-choice--container {
  width: 90%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}
@media (min-width: 768px) {
  main .user-choice--container {
    width: 100%;
  }
}
main .user-choice--container h3 {
  font-size: 2rem;
  color: #757575;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-align: center;
}
main .user-choice--container .user-choice-buttons {
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: space-around;
  margin-top: 30px;
  flex-wrap: wrap;
}
main .user-choice--container .user-choice-buttons > .button {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1.5px;
  font-size: 1.8rem;
  text-align: center;
  width: 150px;
  margin: 10px auto;
  cursor: pointer;
}
@media (min-width: 768px) {
  main .user-choice--container .user-choice-buttons > .button {
    width: 200px;
  }
}
main .user-choice--container .user-choice-buttons > .button:hover > * {
  filter: hue-rotate(145deg) drop-shadow(5px 5px 5px rgba(0, 0, 0, 0.1));
  transform: scale(1.15);
}
main .user-choice--container .user-choice-buttons > .button img {
  width: 120px;
  height: 120px;
  margin-bottom: 10px;
  filter: grayscale(1);
}
@media (min-width: 768px) {
  main .user-choice--container .user-choice-buttons > .button img {
    width: 150px;
    height: 150px;
  }
}
main .help {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e14759;
  color: #fff;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2.5rem;
  font-weight: bold;
  position: absolute;
  bottom: 25px;
  right: 25px;
  cursor: pointer;
}/*# sourceMappingURL=styles.css.map */
              
            
!

JS

              
                // *-*-* SCORES *-*-*
let userScore = 0;
let cpuScore = 0;

const modal = document.querySelector(".result-popup");
const closeModal = document.getElementsByClassName("close-icon")[0];
const userScoreDisplay = document.getElementById("user-score");
const cpuScoreDisplay = document.getElementById("cpu-score");
const help = document.querySelector(".help")
const modalInstructions = document.querySelector(".instructions-popup")
const closeInstructions = document.querySelector(".close-instructions")

let resultDisplay = document.getElementsByClassName("result-display")[0];

const restart = document.getElementById("restart-game");
const resultImage = document.getElementsByClassName("result-image")[0];
const resultUserChoiceImg = document.getElementsByClassName("user-choice-image")[0];
const resultUserChoice = document.getElementsByClassName("user-choice")[0];
const resultCpuChoiceImg = document.getElementsByClassName("cpu-choice-image")[0];
const resultCpuChoice = document.getElementsByClassName("cpu-choice")[0];

//Get user choice on click on buttons
const userOptions = document.querySelectorAll(".button");

closeModal.addEventListener("click", function () {
    modal.style.visibility = 'hidden';
})

document.addEventListener('keydown', function(event){
	if(event.key === "Escape"){
		modal.style.visibility = 'hidden';
        modalInstructions.style.visibility = 'hidden';
	}
});

userOptions.forEach((userOption) => {
    userOption.addEventListener("click", function () {
        const userChoice = this.id;

        const cpuOptions = ["rock", "paper", "scissors", "lizard", "spock"];
        const cpuChoice = () => {
            const randomChoice = Math.floor(Math.random() * 5);
            return cpuOptions[randomChoice];
        }
        let cpuRandomChoice = cpuChoice();
        
        const result = compareChoices(userChoice, cpuRandomChoice);
        if (result == "you win") {
            userScore++
            userScoreDisplay.innerHTML = userScore
            resultDisplay.innerHTML = "YOU WIN!"
            resultImage.src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/win.svg"
            
        } else if (result == "you lose") {
            cpuScore++
            cpuScoreDisplay.innerHTML = cpuScore
            resultDisplay.innerHTML = "YOU LOSE!"
            resultImage.src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/lose.svg"
        } else {
            resultDisplay.innerHTML = "IT'S A TIE!"
            resultImage.src="https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/tie.svg"
        }
        console.log(`User: ${userChoice} // CPU: ${cpuRandomChoice} // Result: ${result}`);
        
        resultUserChoiceImg.src = `https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/${userChoice}.svg`;
        resultUserChoice.innerHTML = userChoice;
        resultCpuChoiceImg.src = `https://osnolaznog.github.io/rock-paper-scissors-lizard-spock/assets/${cpuRandomChoice}.svg`;
        resultCpuChoice.innerHTML = cpuRandomChoice;
        modal.style.visibility = 'visible';

    });
});

restart.addEventListener("click", function (){
    let confirmRestart = confirm("Are you sure you want to restart the game?");
    
    if (confirmRestart == true) {
        userScore = 0;
        cpuScore = 0;
        userScoreDisplay.innerHTML = userScore;
        cpuScoreDisplay.innerHTML = cpuScore;
    } else {
        return false;
    }
    
});

help.addEventListener("click", function(){
    modalInstructions.style.visibility= 'visible';
})

closeInstructions.addEventListener("click", function () {
    modalInstructions.style.visibility = 'hidden';
})

function compareChoices(userChoice, cpuChoice){

    if (userChoice == cpuChoice) {
        return "Empate";
    } else {
        if(userChoice == "rock"){
            if((cpuChoice == "paper") || (cpuChoice == "spock")) {
                return "you lose";
            } return "you win";
        } else if(userChoice == "scissors"){
            if((cpuChoice == "rock") || (cpuChoice == "spock")) {
                return "you lose";
            } return "you win";
        } else if(userChoice == "paper"){ 
            if((cpuChoice == "scissors") || (cpuChoice == "lizard")) {
                return "you lose";
            } return "you win";
        } else if(userChoice == "lizard"){ 
            if((cpuChoice == "scissors") || (cpuChoice == "rock")) {
                return "you lose";
            } return "you win";
        } else if(userChoice == "spock"){ 
            if((cpuChoice == "lizard") || (cpuChoice == "paper")) {
                return "you lose";
            } return "you win";
        }
    }
}
              
            
!
999px

Console