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 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

              
                <div class="div_game">
  <div class="div_scoreBoard">
    <p class="flexCenter p_scoreBoard">Score Board</p>
    <p id="humanScore" class="flexCenter p_humanScore">0</p>
    <p class="flexCenter p_colon">:</p>
    <p id="compScore" class="flexCenter p_compScore">0</p>
  </div><!--socreBoard-->

  <div class="div_choicesBox">
    <div id="humanChoice" class="flexCenter div_choice div_humanChoice">❓</div>
    <p class="flexCenter p_human">Human</p>
    <p class="flexCenter p_vs">VS</p>
    <div id="compChoice" class="flexCenter div_choice div_compChoice">❓</div>
    <p class="flexCenter p_comp">Computer</p>
  </div><!--choicesBox-->

  <div class="div_judgeBox">
    <p class="flexCenter p_judge">👩‍⚖️</p>
    <div class="flexCenter div_result"><p id="result">Hi, I am your judge.</p></div>
  </div><!--judgeBox-->
</div><!--game-->

<div class="div_play">
  <p class="flexCenter p_message">Make your choice!</p>
  <div class="flexCenter div_rps">
    <div id="r" class="flexCenter div_chosen div_r">✊</div>
    <div id="p" class="flexCenter div_chosen div_p">🖐️</div>
    <div id="s" class="flexCenter div_chosen div_s">✌️</div>
  </div>
  <div id="reset" class="flexCenter div_reset">Restart</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');

*{
  padding:0;
  margin:0;
  box-sizing:border-box;
}

html{
  height:100%;
  width:100%;
}

body{
  font-family: 'Montserrat', sans-serif;
  height:100%;
  width:100%;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
}

.flexCenter{
  display:flex;
  justify-content:center;
  align-items:center;
}

.div_game{
  width:50%;
  height:40%;
  margin:1rem 0;
}

.div_scoreBoard{
  width:100%;
  height:30%;
  display:grid;
  grid-template-rows: 50% 50%;
  grid-template-columns:45% 10% 45%;
  text-align:center;
  font-size:2rem;
}

.p_scoreBoard{
  grid-area:1/1/2/4;
  background:black;
  color:white;
  border-top-left-radius:10px;
  border-top-right-radius:10px;
}

.p_humanScore{
  grid-area:2/1/3/2;
}

.p_colon{
  grid-area:2/2/3/3;
}

.p_compScore{
  grid-area:2/3/3/4;
}

.div_choicesBox{
  width:100%;
  height:55%;
  display:grid;
  grid-template-rows: 80% 20%;
  grid-template-columns:45% 10% 45%;
  text-align:center;
}

.div_choice{
  background:#DCDCDC;
  font-size:4rem;
  border:2px solid black;
}

.div_humanChoice{
  grid-area:1/1/2/2;
}

.p_human{
  grid-area:2/1/3/2;
}

.p_vs{
  grid-area:1/2/3/3;
}

.div_compChoice{
  grid-area:1/3/2/4;
}

.p_comp{
  grid-area:2/3/3/4;
}

.div_judgeBox{
  width:100%;
  height:15%;
  display:grid;
  grid-template-columns:20% 80%;
}

.p_judge{
  font-size:2rem;
  grid-column:1/2;
}

.div_result{
  font-size:1.5rem;
  grid-column:2/3;
  border:2px solid black;
  border-top-left-radius:20px;
  border-top-right-radius:20px;
  border-bottom-right-radius:20px;
}

.div_play{
  width:50%;
  height:60%;
  margin:2rem 0;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
}

.p_message{
  height:20%;
  width:100%;
  font-size:2.5rem;
}

.div_rps{
  height:50%;
  width:100%;
}

.div_chosen{
  background:#DCDCDC;
  border:2px solid black;
  border-radius:50%;
  font-size:3rem;
  padding:1rem;
  margin:0.5rem;
  width:100px;
  cursor:pointer;
}

.div_reset{
  background:black;
  color:white;
  font-size:2rem;
  height:30%;
  width:90%;
  padding:1rem;
  margin:0.5rem 0;
  cursor:pointer;
}

@media screen and (max-width:600px){
  .div_game{
    width:90%;
  }

  .div_scoreBoard{
    font-size:1rem;
  }

  .div_choice{
    font-size:2rem;
  }

  .div_judgeBox{
    width:100%;
    height:15%;
    display:grid;
    grid-template-columns:20% 80%;
  }

  .div_result{
    font-size:1rem;
  }

  .div_play{
    width:90%;
  }

  .p_message{
    font-size:1.5rem;
  }

  .div_chosen{
    font-size:1.5rem;
    width:70px;
  }

  .div_reset{
    font-size:1.5rem;
  }
}
              
            
!

JS

              
                //input
const div_r = document.getElementById("r");
const div_p = document.getElementById("p");
const div_s = document.getElementById("s");
const div_reset = document.getElementById("reset");
//output
const p_humanScore=document.getElementById('humanScore');
const p_compScore = document.getElementById('compScore');
const div_humanChoice=document.getElementById('humanChoice');
const div_compChoice=document.getElementById('compChoice');
const p_judgeSay = document.getElementById('result');
const display={
  "r":"✊",
  "p":"🖐️",
  "s":"✌️",
}
//tracking
let humanCurrentScore=0;
let compCurrentScore=0;

function displayResult(result,humanPick,compPick){
  let judgeSay,humanColor,compColor;
  if(result=="draw"){
    judgeSay = "It is a draw!"
    humanColor="#FFD700";
    compColor="#FFD700";
  }else if(result =="win"){
    judgeSay = "Human won!";
    humanCurrentScore++;
    humanColor="green";
    compColor="red";
  }else{
    judgeSay = "Human lost!";
    compCurrentScore++;
    humanColor="red";
    compColor="green";
  }
  p_humanScore.textContent=humanCurrentScore;
  p_compScore.textContent=compCurrentScore;
  p_judgeSay.textContent=judgeSay;
  div_humanChoice.style.background=humanColor;
  div_compChoice.style.background=compColor;
  div_compChoice.textContent = display[compPick];
  div_humanChoice.textContent = display[humanPick];
}

function getCompPick(){
  const choices =["r","p","s"];
  const randomNum=Math.floor(Math.random()*3);
  return choices[randomNum];
}

function game(humanPick){
  let compPick = getCompPick();
  let gameResult;
  switch(humanPick+compPick){
    case "rr":
    case "pp":
    case "ss":
      gameResult="draw";
      break;
    case "rs":
    case "pr":
    case "sp":
      gameResult="win";
      break;
    case "rp":
    case "ps":
    case "sr":
      gameResult="lose";
      break;
  }
  displayResult(gameResult,humanPick,compPick);
}

//input
div_r.addEventListener("click",()=>game("r"));
div_p.addEventListener("click",()=>game("p"));
div_s.addEventListener("click",()=>game("s"));

div_reset.addEventListener("click",function(){
  humanCurrentScore=0;
  compCurrentScore=0;
  p_humanScore.textContent=humanCurrentScore;
  p_compScore.textContent=compCurrentScore;
  div_humanChoice.textContent="❓";
  div_humanChoice.style.background="#DCDCDC";
  div_compChoice.textContent="❓";
  div_compChoice.style.background="#DCDCDC";
  p_judgeSay.textContent="Hi, I am your judge.";
})









              
            
!
999px

Console