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


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


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.


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.


                <div class="title">Current Score:</div>
<div class="score" id="js-score"></div>

<p>Let's add a "New Game" button that resets the score to 0 and updates it</p>

<button onClick="game.newGame()">New Game</button>

<p>Let's simulate an allowed way of updating the game score, using the button to represent the user action .</p>
<button onClick="game.incrementScore()">Increment score (game mechanic)</button>

<p>Let's add an action that simulates end of the game state where we submit the current score to leaderboards</p>

<button onClick="game.gameOver()">Game Over</button>

<div class="explanation">
  <p>Open the Console by clicking the button below below. Try using <code>setScore(500)</code> function to manipulate the score and <code>gameOver()</code> function to submit the score.</p>


                body {
  font-family: sans-serif;
  font-size: 1.25rem;
  max-width: 768px;
  margin: 0 auto;
  padding: 1rem;
  line-height: 1.333;

.score {
    font-size: 3rem;
  text-align: center;

.title {
  font-size: 1.5rem;
    text-align: center;


                const game = (() => {
  let score = 0;
  let scoreContainer;

  const updateScore = newScore => {
    if (isNaN(newScore)) return;
    score = newScore;
    scoreContainer.innerHTML = score;

  const incrementScore = () => {
    updateScore(score + 1);

  const submitScore = () => alert("Submitting Score: " + score);

  const gameOver = () => submitScore();

  const newGame = () => {

  const init = () => {
    scoreContainer = document.getElementById("js-score");


  return {