css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JS Bin</title>
  <link rel="stylesheet" type="text/css" href="April.css">
</head>

<body>
  
  <div id="container">
    <div id="playerScore" class = "healthBar">Player
        <br> 0</div>
    <p id="resuult"></p>
    <div id="compScore" class = "healthBar">Computer
        <br> 0</div>

    <div class="rock RPSboxes">
      <button id="rockBut">Rock</button>
    </div>
    <div id="paper" class = "RPSboxes">
      <button id="paperBut">Paper</button>
    </div>

    <div id="scissors"  class = "RPSboxes">
      <button id = "scissorsBut">Scissors</button>
    </div>

    
    <div id="demo" class="demo-prompt">
      <p>Click Rock, Paper or Scissors</p> 
    </div>


    <audio id="scisound" src="https://www.dropbox.com/s/rtwvlnodo9h6uhv/scissors.mp3?raw=1" autostart="false"></audio>
    <audio id="papsound" src="https://www.soundjay.com/misc/sounds/paper-rustle-4.mp3" autostart="false"></audio>
    <audio id="roksound" src="https://www.soundjay.com/mechanical/sounds/smack-1.mp3" autostart="false"></audio>
  </div>

</body>

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

</html>
            
          
!
            
              * {
    box-sizing: border-box;
}

*{
margin:0;
padding:0;
}

body{font-weight:bold;}

.healthBar{border: solid black .1em;
    border-radius: .5em;
    align-items: center;
    text-align: center;
    display: flex;
    justify-content: center;
    position:absolute;
    top:20px;
    height:5%;
    width: 25%;
    background-position:center;
    background-repeat:no-repeat;
    background-size:107% 300%;
    padding:10px;}

#playerScore {
    left:30px;   
background-image:url(https://user-images.githubusercontent.com/31823017/39405164-18386a7c-4b98-11e8-9a68-bf7d09639637.png);
}


#compScore {
    right: 30px;
    background-image:url(https://user-images.githubusercontent.com/31823017/39405164-18386a7c-4b98-11e8-9a68-bf7d09639637.png);
}

.rock {
  background-color:lightslategray;
background-image: url(https://user-images.githubusercontent.com/31823017/37183020-ecec6718-232b-11e8-89d4-a0a3a90c76dc.jpg);
 background-size: 150% 120%;
 grid-area:3/1/4/2;
}


#paper {
grid-area:3/2/4/3;
background-color:rgba(57, 93, 148, 0.322) ;
background-image: url(
https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT3V69i4JxaMa89A9PHIhTSqcVHfUifpovhfz7Mp4bSvhTPUu1U);
background-size:95% 95%;
}

#scissors {
grid-area:3/3/4/4;
background-color: #cccccc;
background-image: url(http://www.clipartlord.com/wp-content/uploads/2016/08/scissors7-232x240.png);
background-size: 85% 85%;
}

.RPSboxes
{margin:10px 0px 0px 0px;
border: solid black 3px;
background-position:center;
align-items:center;
background-repeat:no-repeat;
justify-content:center;
display:flex;
}

button{padding:6px;
    background-color: beige;
    font-size: 20px;
    color: red;
    border: 2px solid #4CAF50;

}
button:hover{background-color: #4CAF50;
    color: white;
}
button:active {
    background-color: #3e8e41;
    box-shadow: 0 5px #666;
    transform: translateY(4px);
  }


.largefont { 
    color: red; 
    font-weight:bold;
    font-family:arial; 
    text-transform: uppercase;
}

#demo {
    text-align: center;
    display:flex;
    grid-area:2/2/3/3;
    align-content: center;
    justify-content: center;
    align-items:center;
    
}

.demo-prompt {
    color: black;
    font-size: 1.5rem;
    grid-area:2/2/3/4;
    align-content: center;
    justify-content: center;
}


.demo-result {
    padding:10px;
    font: 1.5em Georgia;
    color: black;
    transition: rotate 2s;
    position:absolute;
    top: 5%;
    left:35%;
    z-index:1;
    width: 25%;
    height:12%;
}

#resuult {text-align: center;
    position:absolute;
    color:blue;
    top: 15%;
    left:25%;
    width: 50%;
    max-height:5%;
    z-index:5;
    font-size:5em;
  }

 #container {
    background-image:url('https://user-images.githubusercontent.com/31823017/39372908-bb7947a8-4a3d-11e8-8f0a-c1cd210d1575.png'); 
  background-size:100% 100%;
   display:grid;
   grid-template-columns:minmax(200px, 2fr) minmax(200px, 2fr) minmax(200px, 2fr);
   grid-template-rows: .5fr 1fr 5fr 2fr;
   height:100vh;
   padding:0px 15px;
   grid-column-gap: 15px;
   font-size:16px;
   }

  @media only screen and (max-width:600px) {
    #container {
       grid-template-columns: minmax(95px, 2fr) minmax(95px, 2fr) minmax(95px, 2fr) ;}
   .rock {
    background-color:rgb(115, 159, 196);
 background-size: 180% 90%;
}

.demo-prompt{
    font-size:1em;
}

}
            
          
!
            
              playerScore = 0;
compScore = 0;

// this function creates a random number from 1-3
function oneToThree() {
  res = Math.floor(Math.random() * 3) + 1;
  const containerdem = document.getElementById("demo");

  //clear container before we add new elements
  containerdem.innerHTML = "";

  //remove the css class for prompting the user
  containerdem.classList.remove("demo-prompt");

  //we use this paragraphs for all our conditions so we right here only once

  // this paragraph gets created only when the oneToThree function runs
  const p = document.createElement("p");
  p.textContent = "Computer chose ";
  p.classList.add("demo-result"); 

  //Create the span the result is going into
  const result = document.createElement("span");

  if (res === 3) {
    result.textContent = "rock";
  } else if (res === 2) {
    //PAPER
    result.textContent = "paper";
  } else {
    //MUST BE SCISSOR
    result.textContent = "scissor";
  }

  //do operations after the conditions instead of inside each condition to avoid duplication
  result.classList.add("largefont");
  p.appendChild(result);

  containerdem.appendChild(p);

  function playGame() {
    if (playerChoice === "ROCK" && res === 3) {
      document.getElementById("resuult").innerHTML = "DRAW!";
    } else if (playerChoice === "ROCK" && res === 2) {
      document.getElementById("resuult").innerHTML = "You LOSE!";
      compScore++;
      document.getElementById("compScore").innerHTML = compScore;
    } else if (playerChoice === "ROCK" && res <= 1.99) {
      document.getElementById("resuult").innerHTML = "You WIN!";
      playerScore++;
      document.getElementById("playerScore").innerHTML = playerScore;
    } else if (playerChoice === "SCISSORS" && res <= 1.99) {
      document.getElementById("resuult").innerHTML = "DRAW!";
    } else if (playerChoice === "SCISSORS" && res === 3) {
      document.getElementById("resuult").innerHTML = "You LOSE!";
      compScore++;
      document.getElementById("compScore").innerHTML = compScore;
    } else if (playerChoice === "SCISSORS" && res === 2) {
      document.getElementById("resuult").innerHTML = "You WIN!";
      playerScore++;
      document.getElementById("playerScore").innerHTML = playerScore;
    } else if (playerChoice === "PAPER" && res === 2) {
      document.getElementById("resuult").innerHTML = "DRAW!";
    } else if (playerChoice === "PAPER" && res === 3) {
      document.getElementById("resuult").innerHTML = "You WIN!";
      playerScore++;
      document.getElementById("playerScore").innerHTML = playerScore;
    } else if (playerChoice === "PAPER" && res <= 1.99) {
      document.getElementById("resuult").innerHTML = "You LOSE!";
      compScore++;
      document.getElementById("compScore").innerHTML = compScore;
    }
    if (compScore === 1) {
      document.getElementById("playerScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405166-2630be9a-4b98-11e8-8904-f93554cbbdab.png')";
    }
    if (compScore === 2) {
      document.getElementById("playerScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405170-31ec2b98-4b98-11e8-8dad-c79b664995ff.png')";
    }
    if (compScore === 3) {
      document.getElementById("playerScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405169-31cfb486-4b98-11e8-8bdb-97cd112b74ee.png')";
    }
    if (compScore === 4) {
      document.getElementById("playerScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405168-31b19884-4b98-11e8-829a-7514ca785953.png')";
    }
    // the timeOut thing delays in milliseconds how long until the Alert shows up, location.reload and refreshes the page if you click ok.
    if (compScore === 5) {
      document.getElementById("playerScore").style.backgroundImage = "url('')";
      setTimeout(delayedReload, 1000);
      function delayedReload() {
        alert("Game Over! Play again?");
        location.reload();
      }
    }

    if (playerScore === 1) {
      document.getElementById("compScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405166-2630be9a-4b98-11e8-8904-f93554cbbdab.png')";
    }
    if (playerScore === 2) {
      document.getElementById("compScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405170-31ec2b98-4b98-11e8-8dad-c79b664995ff.png')";
    }
    if (playerScore === 3) {
      document.getElementById("compScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405169-31cfb486-4b98-11e8-8bdb-97cd112b74ee.png')";
    }
    if (playerScore === 4) {
      document.getElementById("compScore").style.backgroundImage =
        "url('https://user-images.githubusercontent.com/31823017/39405168-31b19884-4b98-11e8-829a-7514ca785953.png')";
    }
    if (playerScore === 5) {
      document.getElementById("compScore").style.backgroundImage = "url('')";
      setTimeout(delayedReload, 1000);
      function delayedReload() {
        alert("Game Over! Play again?");
        location.reload();
      }
    }
  }

  rockBut.addEventListener("click", playGame());
}
function playSoundS() {
  var sound = document.getElementById("scisound");
  sound.play();
}
function playSoundP() {
  var sound = document.getElementById("papsound");
  sound.play();
}
function playSoundR() {
  var sound = document.getElementById("roksound");
  sound.play();
}





rockBut.addEventListener("click", oneToThree);
rockBut.addEventListener("click", playSoundR);
rockBut.addEventListener("click", function colorText() {
  document.getElementsByClassName(
    "demo-result"
  )[0].style.color = randomColor();
});
paperBut.addEventListener("click", playSoundP);
paperBut.addEventListener("click", oneToThree);

paperBut.addEventListener("click", function colorText() {
  document.getElementsByClassName(
    "demo-result"
  )[0].style.color = randomColor();
});

scissorsBut.addEventListener("click", playSoundS);
scissorsBut.addEventListener("click", oneToThree);
scissorsBut.addEventListener("click", function colorText() {
  document.getElementsByClassName(
    "demo-result"
  )[0].style.color = randomColor();
});
        

function randomColor() {
  var randomRed = Math.floor(Math.random() * 255);
  var randomGreen = Math.floor(Math.random() * 255);
  var randomBlue = Math.floor(Math.random() * 255);
  //create the string that is the ‘random color’
  var randomColor =
    "rgb(" + randomRed + "," + randomGreen + "," + randomBlue + ")";

  return randomColor;
}

// playerChoice is just the string that shows up in text what you clicked on
let playerChoice = "";
rockBut.addEventListener("click", function() {
  playerChoice = "ROCK";
});

scissors.addEventListener("click", function() {
  playerChoice = "SCISSORS";
});

paper.addEventListener("click", function() {
  playerChoice = "PAPER";
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console