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

              
                <nav class="navbar">
  <div class="container">
    <ul class="nav">
      <li class="active"><a href="#">Home</a></li>
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2</a></li>
      <li><a href="#">Link 3</a></li>
    </ul>
  </div>
</nav>

<div class="container">
  <h1>Rock, Paper, Scissors...</h1>
  
  <p>Challenge your console to a quick game <small>(or several)</small> of Rock, Paper, Scissors. Just click the pretty pink button below to play as many times as you want.</p>
  
  <button class="btn" type="button" onclick="playGame(); i++;">Play Game &raquo;</button>
  
  <div class="results">
    <h2>Results</h2>
    <p><small>The results of each game will populate in the box below:</small></p>
    
    <div id="RPSResults">
      
    </div>
  </div>
  
  <footer>&copy; RPS Games</footer>
</div>
              
            
!

CSS

              
                *{
  color:#333;
  margin:0;
  padding:0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
h1, h2, h3 {font-family: Georgia, serif;}
h1 {margin-bottom: 15px;}
p {margin-bottom:10px;}
small {color:#999;}
.container {
  padding: 0 20px;
  margin: 0 auto;
  max-width: 900px;
  min-width: 300px;
}
.navbar {
  min-height: 50px;
  background-color: #f8f8f8;
  border-bottom: 1px solid #e7e7e7;
  margin-bottom: 40px;
}
.nav {
  margin:0;
  list-style:none;
}
.nav li {
  float:left;
  display:block;
}
.nav li a {
  text-decoration:none;
  color:#777;
  display: block;
  padding: 16px 16px 12px;
  font-size:16px;
  line-height:22px;
}
.nav li a:hover {
  background-color: #eee;
}
.nav li.active a, .nav li.active a:hover {
  background-color:#ddd;
}
button {
  clear: left;
  float: left;
  margin: 15px auto 22px;
  width: 100%;
}
.btn {
  cursor: pointer;
  display: inline-block;
  background-color: hsl(0, 100%, 82%);
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#fecccc", endColorstr="#fea3a3");
  background-image: -khtml-gradient(linear, left top, left bottom, from(#fecccc), to(#fea3a3));
  background-image: -moz-linear-gradient(top, #fecccc, #fea3a3);
  background-image: -ms-linear-gradient(top, #fecccc, #fea3a3);
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fecccc), color-stop(100%, #fea3a3));
  background-image: -webkit-linear-gradient(top, #fecccc, #fea3a3);
  background-image: -o-linear-gradient(top, #fecccc, #fea3a3);
  background-image: linear-gradient(#fecccc, #fea3a3);
  border-color: #fea3a3 #fea3a3 hsl(0, 100%, 80%);
  color: #333;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: normal;
  padding: 9px 14px 9px;
  border-radius: 6px;
  border: 1px solid #fea3a3;
}
.btn:hover {
  background-image: -khtml-gradient(linear, left top, left bottom, from(#fcb3b3), to(#fc8888));
  background-image: -moz-linear-gradient(top, #fcb3b3, #fc8888);
  background-image: -ms-linear-gradient(top, #fcb3b3, #fc8888);
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fcb3b3), color-stop(100%, #fc8888));
  background-image: -webkit-linear-gradient(top, #fcb3b3, #fc8888);
  background-image: -o-linear-gradient(top, #fcb3b3, #fc8888);
  background-image: linear-gradient(#fcb3b3, #fc8888);
  border: 1px solid #de8e8e;
}
.results {
  clear:both;
}
#RPSResults {
  max-width: 900px;
  height: 372px;
  overflow-y: auto;
  border: 1px solid #ccc;
  border-left: 6px solid #fcb3b3;
  background-color:#f8f8f8;
}
.round {
  position: relative;
  border-left:3px solid #777;
  margin:15px;
}
.round p {
  color:#333;
  padding-left: 10px;
}
.round p.counter {
  position: absolute;
  top: 15px;
  right: 0;
  font-size: 12px;
  font-weight: 700;
  color: #ccc;
  text-transform: uppercase;
}
.compChoice {padding-top:10px;}
.result {
  background-color:#e7e7e7;
  padding:10px;
  font-weight:bold;
}
.win {
  background-color: #FFCFCF;
}
footer {
  min-height:30px;
  margin-top: 20px;
  padding: 10px 0;
  color: #bbb;
  text-align: right;
  border-top: 1px solid #e5e5e5;
  font-size: 14px;
}

@media (min-width: 640px) {
  .btn {
    max-width:300px;
    float:right;
  }
}
              
            
!

JS

              
                var i = 1;

function getUserChoice(){
  userChoice = prompt("Do you choose rock, paper or scissors?");
  console.log(userChoice);
}

function getComputerChoice (){
  computerChoice = Math.random();
  
  if (computerChoice < 0.34) {
    computerChoice = "rock";
  } else if(computerChoice <= 0.67) {
    computerChoice = "paper";
  } else {
    computerChoice = "scissors";
  }
  
  var a = document.createElement("p");
  var b = document.createTextNode("Computer: " + computerChoice);
  a.appendChild(b);
  a.classList.add("compChoice");
  document.getElementById("round" + i).appendChild(a);
  console.log(computerChoice);
}

function validateUserChoice(){
  userChoice = userChoice.toLowerCase();
  choices = ["rock", "paper", "scissors"];
  isValid = choices.indexOf(userChoice);
  
  var c = document.createElement("p");
  
  if (isValid > -1) {
    var d = document.createTextNode("You: " + userChoice);
    c.appendChild(d);
    c.classList.add("userChoice");
    document.getElementById("round" + i).appendChild(c);
    return true;
  } else {
    alert("That is not a valid option. Try again.");
    var d = document.createTextNode("You: " + userChoice + " - invalid, try again. ");
    c.appendChild(d);
    c.classList.add("userChoice");
    document.getElementById("round" + i).appendChild(c);
    return false;
  } 
}

function determineWinner (choice1, choice2) {
  if (choice1 === choice2) {
        var f = document.createTextNode("The result is a tie!");
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            var f = document.createTextNode("Rock wins!");
        } else {
            var f = document.createTextNode("Paper wins!");
        }
    }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {
            var f = document.createTextNode("Paper wins!");
        } else {
            var f = document.createTextNode("Scissors wins!");
        }
    }
    else if (choice1 === "scissors") {
        if (choice2 === "rock") {
            var f = document.createTextNode("Rock wins!");
        } else {
            var f = document.createTextNode("Scissors wins!");
        }
    }
  var e = document.createElement("p");
  e.classList.add("result");
  e.appendChild(f);
  document.getElementById("round" + i).appendChild(e);
}

function roundTracker () {
  var g = document.createElement("p");
  var h = document.createTextNode("Round " + i);
  g.classList.add("counter");
  g.appendChild(h);
  document.getElementById("round" + i).appendChild(g);
}

function playGame(){ 
  do {
    var displayResults = document.createElement("div");
    displayResults.classList.add("round");
    displayResults.setAttribute("id", "round" + i);
    document.getElementById("RPSResults").appendChild(displayResults);
    
    getUserChoice();
    getComputerChoice ();
    roundTracker();
    isValidChoice = validateUserChoice();
  } while (isValidChoice === false);
  
  determineWinner (userChoice, computerChoice);
  
  var showLatest = document.getElementById("RPSResults");
  showLatest.scrollTop = showLatest.scrollHeight;
}
              
            
!
999px

Console