Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!-- By Lorenzo Satta Chiris  -->

<h1 class="header">Rock Paper Scissors Game</h1>

    <span class="userInput" id="user"></span>
    <div class="scoreboard" id="score">
        <span class="user">User</span>
        0:0
        <span class="comp">Comp</span>
    </div>
    <span class="compInput" id="comp"></span>

    <div class="moves">
        <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANwAAADlCAMAAAAP8WnWAAAAhFBMVEX39/f///8AAAD6+vr8/Pzw8PD19fXp6ent7e3ExMS2trbk5OTS0tKQkJB2dnbJycmdnZ3d3d2Hh4fX19erq6u8vLxBQUFGRkZYWFiBgYG4uLjOzs43NzdLS0uYmJhxcXGNjY1eXl5qamoZGRkrKysvLy87OzsSEhIhISFjY2OkpKQUFBRNCYJmAAAN40lEQVR4nO1d6ZqiOhQkhwCyiAvgDq6ttv3+7zdJUBQ1YdMQ57N+9e3rzFAmOWvloGlffPHFF1988cUX/xd0jDCB3vZzvB66pvf8zTIJHc9E/xU/HWv2oGdbpuvaU4DxDOG2H+llQF5/rqMMQbKDfuf/WD69M7TRHdwlbIL/YPlwEN5To8AJ7GefvnrY6z7jRuHAaI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M45vNKQgsjypWYwuBb5sCB15gaX+UObkCufm4ZPMsLT9CO3KMxiB7013m/Hb/3vXRhWuzx9gIOjLDnNP23fuFkzpB79VA7iq3eslNOkv9vZpviC8LHWluria2HNxsSgm34t4MXUedcPOX0duNSNpqMYGGku2PqtAx0mdruMcHJHIlgVGwyXOTMqVMFoj17F8Dsw91cQJg5HX9xRZgP5T82kMp0KkzID6i7dc1f/HFF1988cUXX0jFPxFcyrdXQLWyAAAAAElFTkSuQmCC"
            alt="rock" class="r" id="r">
        <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ1k6UWzr7o7UjOPUCYjyRLSKc6yIvuHeYgVg&usqp=CAU"
            alt="paper" class="p" id="p">
        <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSOKJuwxHZqnQfmH6lJxI4qzux0ERHNKMDpkw&usqp=CAU"
            alt="scissor" class="s" id="s">
    </div>

    <p class="moveInfo" id="utility">Make your move</p>

<div class="info">
  <a href="https://codepen.io/DevLorenzo" target="_blank" class="info1">My profile page</a>
  <a href="https://codepen.io/DevLorenzo/pen/LYRJbVw" target="_blank" class="info2">My most visited Pen</a>
  <a href="https://www.codegrepper.com/app/profile.php?id=182534" target="_blank" class="info3">Grepper profile</a>
</div>
              
            
!

CSS

              
                /* By Lorenzo Satta Chiris */

@import url("https://fonts.googleapis.com/css2?family=Asap:ital,wght@0,400;0,600;1,500&display=swap");

body {
  background: linear-gradient(
    -45deg,
    #ee7752,
    #e73c7e,
    #23a6d5,
    #23d5ab,
    #333642
  );
  background-size: 400% 400%;
  animation: gradient 15s ease infinite;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.header {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #1d1e22;
  margin-top: -10px;
  padding: 23px 0;
  color: whitesmoke;
  font-family: "Asap", sans-serif;
}

.scoreboard {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: -22px;
  padding: 15px 5px;
  border: 2px solid #333642;
  border-width: 5px 650px;
  color: #333642;
  font-family: "Asap", sans-serif;
  font-size: 30px;
}

.user {
  background-color: red;
  position: relative;
  left: -90px;
  font-size: 18px;
}

.comp {
  background-color: red;
  position: relative;
  right: -95px;
  font-size: 18px;
}

.userInput {
  font-weight: bold;
  font-family: "Asap", sans-serif;
  position: absolute;
  left: 200px;
  top: 105px;
  font-size: 25px;
  color: red;
}

.compInput {
  font-weight: bold;
  font-family: "Asap", sans-serif;
  position: absolute;
  right: 200px;
  top: 105px;
  font-size: 25px;
  color: red;
}

.moves {
  display: flex;
  justify-content: center;
  align-items: center;
  color: whitesmoke;
  font-family: "Asap", sans-serif;
  font-size: 30px;
  margin-top: 15px;
  margin-left: 5px;
}

.r {
  border: 1px solid red;
  border-width: 3px;
  border-radius: 50%;
  margin-right: 20px;
  border-right: none;
}

.r:hover {
  border-color: #c31432;
  animation: spin 10s ease infinite;
  border-width: 8px;
}

.p {
  padding: 2px;
  border: 1px solid red;
  border-width: 3px;
  border-radius: 50%;
  border-left: none;
  border-right: none;
}

.p:hover {
  border-color: #c31432;
  animation: spin 10s ease infinite;
  border-width: 8px;
}

.s {
  padding: 2px;
  border: 1px solid red;
  border-width: 3px;
  border-left: none;
  border-radius: 50%;
  margin-left: 20px;
}

.s:hover {
  border-color: #c31432;
  animation: spin 10s ease infinite;
  border-width: 8px;
}

@keyframes spin {
  0% {
    border-color: #c31432;
  }
  50% {
    border-position: 100% 50%;
    border-color: #240b36;
  }
  100% {
    border-position: 0% 50%;
    border-color: #240b36;
  }
}

.moveInfo {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #1d1e22;
  font-family: "Asap", sans-serif;
  font-size: 40px;
  margin-top: 25px;
  margin-left: 5px;
}

.info {
  display: flex;
  justify-content: center;
  align-items: center;
  color: whitesmoke;
  font-family: "Asap", sans-serif;
  font-size: 35px;
  margin-top: 15px;
  margin-left: 5px;
  text-decoration: none;
}

.info1 {
  border: 1px solid red;
  border-width: 3px;
  border-radius: 50%;
  margin-right: 20px;
  border-right: none;
  padding: 20px;
  color: inherit;
  text-decoration: inherit;
}

.info1:hover {
  border-color: #c31432;
  border-width: 8px;
  padding: 25px;
  background: linear-gradient(
    -45deg,
    #bdc3c7,
    #2c3e50,
    #c33764,
    #1d2671,
    #141e30,
    #6dd5ed
  );
  background-size: 400% 400%;
  animation: backgroundChange 15s ease infinite, spin 10s ease infinite;
}

.info2 {
  padding: 2px;
  border: 1px solid red;
  border-width: 3px;
  border-radius: 50%;
  border-left: none;
  border-right: none;
  padding: 20px;
  color: inherit;
  text-decoration: inherit;
}

.info2:hover {
  border-color: #c31432;
  border-width: 8px;
  padding: 25px;
  background: linear-gradient(
    -45deg,
    #bdc3c7,
    #2c3e50,
    #c33764,
    #1d2671,
    #141e30,
    #6dd5ed
  );
  background-size: 400% 400%;
  animation: backgroundChange 15s ease infinite, spin 10s ease infinite;
}

.info3 {
  padding: 2px;
  border: 1px solid red;
  border-width: 3px;
  border-left: none;
  border-radius: 50%;
  margin-left: 20px;
  padding: 20px;
  color: inherit;
  text-decoration: inherit;
}

.info3:hover {
  border-color: #c31432;
  border-width: 8px;
  padding: 25px;
  background: linear-gradient(
    -45deg,
    #bdc3c7,
    #2c3e50,
    #c33764,
    #1d2671,
    #141e30,
    #6dd5ed
  );
  background-size: 400% 400%;
  animation: backgroundChange 15s ease infinite, spin 10s ease infinite;
}

@keyframes backgroundChange {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

              
            
!

JS

              
                // By Lorenzo Satta Chiris

let rock = document.getElementById("r");
let paper = document.getElementById("p");
let scissors = document.getElementById("s");
let score = document.getElementById("score");
let userWrite = document.getElementById("user");
let computerWrite = document.getElementById("comp");
let utility = document.getElementById("utility");
let computerChoice;
let userScore = 0;
let computerScore = 0;

document.getElementById("r").addEventListener("click", function () {
  game("r");
});
document.getElementById("p").addEventListener("click", function () {
  game("p");
});
document.getElementById("s").addEventListener("click", function () {
  game("s");
});

function getComputerChoice() {
  let random = Math.floor(Math.random() * 3);
  if (random === 0) {
    return "p";
  } else if (random === 1) {
    return "s";
  }
  return "r";
}

function convertToWord(letter) {
  if (letter === "r") return "rock";
  if (letter === "p") return "paper";
  return "scissors";
}

function game(userChoice) {
  computerChoice = getComputerChoice();
  switch (userChoice + computerChoice) {
    case "rs":
    case "pr":
    case "sp":
      win(userChoice, computerChoice);
      break;
    case "rp":
    case "ps":
    case "sr":
      lose(userChoice, computerChoice);
      break;
    case "rr":
    case "pp":
    case "ss":
      draw(userChoice, computerChoice);
      break;
  }
}

function win(userChoice, computerChoice) {
  userScore++;
  score.innerHTML = userScore + " : " + computerScore;
  userWrite.innerHTML = "You played " + convertToWord(userChoice);
  computerWrite.innerHTML = "Computer played " + convertToWord(computerChoice);
  utility.innerHTML = "Great win!";
  if (userScore == 10) {
    setTimeout(() => {
      utility.innerHTML = "GG You reached 10 points!";
    }, 1000);
  }
  if (userScore == 50) {
    setTimeout(() => {
      utility.innerHTML = "WOW! 50 points!!!!!";
    }, 1000);
  }
}

function lose(userChoice, computerChoice) {
  computerScore++;
  score.innerHTML = userScore + " : " + computerScore;
  userWrite.innerHTML = "You played " + convertToWord(userChoice);
  computerWrite.innerHTML = "Computer played " + convertToWord(computerChoice);
  utility.innerHTML = "You losed ):";
}

function draw(userChoice, computerChoice) {
  userWrite.innerHTML = "You played " + convertToWord(userChoice);
  computerWrite.innerHTML = "Computer played " + convertToWord(computerChoice);
  utility.innerHTML = "It's a Draw!";
}

              
            
!
999px

Console