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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap" rel="stylesheet">
    <title>GameChooser</title>
</head>
<body> 
  <div class="chooser">
    <h1>What Game Should I Play?</h1>
    <h4>Created for the most indecisive of gamer...</h4>

   <button type="button" id="generate" class="generate">Decide!</button>

    <p>You should play <span>...</span>🕹.</p>
  </div>
  <div class="customList">
    <form id="gamesForm">
    <input id="gamesInput" type="text">
    <button type="button" id="button" class="add">Add Game</button>
     
     <button type="button" class="refresh">Clear Games</button>
      
    </form>
  <h4>Your Games:</h4>
    <ol id="gamesList"></ol>
  </div>
</body>
</html>
              
            
!

CSS

              
                * {
	background: #ccccd4;
	font-family: 'Press Start 2P', cursive;
  -webkit-font-smoothing: none;
}

.chooser {
	text-align: center;
}

.customList {
  text-align: center;
  padding-top: 2%;
}


h1,
p {
	color: white;
}

h4 {
	color: #64676e;
}

button {
	background: #64676e;
  color: white;
	padding: 20px;
	border-radius: 10px;
}

button.refresh {
  background: #57C095;
}

button.add {
  background: #E5432F;
}


span {
	color: white;
}

input {
  background: white;
  padding: 20px;
	border-radius: 10px;
  margin-right: 20px;
}

ol {
  font-size: 15px;
  color: #64676e;
  list-style-type: none;
}

/* TO DO 
- Responsive design
*/
              
            
!

JS

              
                const colours = [ '#57C095', '#2151AE', '#D4A609', '#E5432F' ];

var games = [];

$(document).ready(function() {
	$('button.generate').on('click', function() {
		//console.log('Decide Button Pressed');

		var randomGame = games[Math.floor(Math.random() * games.length)];
		var randomColour = colours[Math.floor(Math.random() * colours.length)];

		var chosenGame = randomGame;

		$('span').text(chosenGame);
		$('span').css('color', randomColour);
		$('button.generate').text('Try again?');
	});
  
  
  $('button.add').on('click', function() {
    //console.log('Add Button Pressed');
    
    var list = document.getElementById('gamesList');
    list.innerHTML = '';
    
    var gamesInput = document.getElementById('gamesInput').value;
    games.push(gamesInput);
    
    var item = document.createElement("li");
    for (var i = 0; i < games.length; i++) 
      {
        var listItem = document.createTextNode(games[i]);
        var li = document.createElement("li");
        li.appendChild(document.createTextNode(games[i]));
        list.append(li);
      }
  });
  
  
  $('button.refresh').on('click', function() {
    console.log('Refresh Button Pressed');
    var list = document.getElementById('gamesList');
 list.innerHTML = '';
    games = [];
   });
});

// TO DO 
// Work out why jquery sometimes doesn't work

              
            
!
999px

Console