Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <header>
  <h1>Fool's Mate</h1>
  <p>In chess, Fool's Mate, also known as the Two-Move Checkmate, is the checkmate in the fewest possible number of moves from the start of the game. This can be achieved only by Black, who can deliver checkmate on move 2 with the queen. Fool's Mate received its name because it can only occur if White commits an extraordinary blunder. Even among rank beginners, the mate almost never occurs in practice.</p>
</header>

<main>
  <div class="grid board">
    <div class="grid__item piece">♜</div>
    <div class="grid__item piece">♞</div>
    <div class="grid__item piece">♝</div>
    <div class="grid__item piece">♚</div>
    <div class="grid__item piece">♝</div>
    <div class="grid__item piece">♞</div>
    <div class="grid__item piece">♜</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row8">♖</div>
    <div class="grid__item piece row8">♘</div>
    <div class="grid__item piece row8">♗</div>
    <div class="grid__item piece row8">♕</div>
    <div class="grid__item piece row8">♔</div>
    <div class="grid__item piece row8">♗</div>
    <div class="grid__item piece row8">♘</div>
    <div class="grid__item piece row8">♖</div>
  </div>

  <div class="move1 grid">
    <div class="piece"><span>♙</span></div>
  </div>

  <div class="move2 grid">
    <div class="piece"><span>♟</span></div>
  </div>

  <div class="move3 grid">
    <div class="piece"><span>♙</span></div>
  </div>

  <div class="move4 grid">
    <div class="piece"><span>♛</span></div>
  </div>
</main>

<div class="controls">
  <button type="button" id="prev">Prev</button>
  <button type="button" id="next">Next</button>
</div>
              
            
!

CSS

              
                @font-face {
  font-family: "Emoji";
  src: local("Apple Color Emoji"), local("Segoe UI Emoji"), local("Segoe UI Symbol"), local("Noto Color Emoji");
}

body {
  display: flex;
  flex-direction: column;
  text-align: center;
  align-items: center;
}

p {
  line-height: 1.4;
}

.board {
  background-color: #eee;
  background-image: linear-gradient(45deg, #d18b47 25%, transparent 25%, transparent 75%, #d18b47 75%, #d18b47),
  linear-gradient(45deg, #d18b47 25%, transparent 25%, transparent 75%, #d18b47 75%, #d18b47);
  background-size: 24vmin 24vmin;
  background-position: 0 0, 12vmin 12vmin;
  width: 96vmin;
  height: 96vmin;
  margin: auto;
}

.piece {
  font-size: 6vmin;
  font-family: "Emoji";
}

main {
  position: relative;
  height: 96vmin;
  width: 96vmin;
}

.grid {
  display: grid;
  position: absolute;
}

.board {
  grid-template-columns: repeat(8, 12vmin);
  grid-template-rows: repeat(8, 12vmin);
}

.board .grid__item {
  margin: auto;
}

.board .piece:nth-child(4) { grid-column: 5 }
.board .piece:nth-child(12) { grid-column: 6 }
.board .piece:nth-child(20) { grid-column: 8 }
.row7 { grid-row: 7 }
.row8 { grid-row: 8 }

[class^="move"] {
  height: 100%;
  width: 100%;
}

[class^="move"] .piece {
  height: 12vmin;
  width: 12vmin;
  display: flex;
  place-self: end;
}

[class^="move"] span {
  margin: auto;
}

.move1 {
  grid-template-columns: 72vmin 1fr;
  grid-template-rows: 84vmin 1fr;
  transition: grid-template-rows 0.5s linear;
}

.move1.active {
  grid-template-rows: 72vmin 1fr;
}

.move2 {
  grid-template-columns: 60vmin 1fr;
  grid-template-rows: 24vmin 1fr;
  transition: grid-template-rows 0.75s linear;
}

.move2.active {
  grid-template-rows: 48vmin 1fr;
}

.move3 {
  grid-template-columns: 84vmin 1fr;
  grid-template-rows: 84vmin 1fr;
  transition: grid-template-rows 0.75s linear;
}

.move3.active {
  grid-template-rows: 60vmin 1fr;
}

.move4 {
  grid-template-columns: 48vmin 1fr;
  grid-template-rows: 12vmin 1fr;
  transition: grid-template-columns 1.25s linear, grid-template-rows 1.25s linear;
}

.move4.active {
  grid-template-columns: 96vmin 1fr;
  grid-template-rows: 60vmin 1fr;
}

.controls {
  width: 36vmin;
  display: flex;
  margin-top: 1em;
  justify-content: space-around;
}

button {
  font-size: initial;
  background-color: #d18b47;
  border: none;
  padding: 0.5em 0.75em;
  cursor: pointer;
}
              
            
!

JS

              
                const prevBtn = document.getElementById('prev')
const nextBtn = document.getElementById('next')

let moves = 0

prevBtn.addEventListener('click', prevHandler, false)
nextBtn.addEventListener('click', nextHandler, false)

function nextHandler() {
  if (moves < 4) {
    countUp()
    addActive(moves)
    console.log(moves)
  } else {
    console.log('Already checkmate')
  }
}

function prevHandler() {
  if (moves > 0) {
    removeActive(moves)
    countDown()
    console.log(moves)
  } else {
    console.log('Back to the start')
  }
}

function addActive(moves) {
  const activeMove =  document.querySelector('.move' + moves)
  activeMove.classList.add('active')
}

function removeActive(moves) {
  const activeMove =  document.querySelector('.move' + moves)
  activeMove.classList.remove('active')
}

function countUp() {
  return moves++
}

function countDown() {
  return moves--
}
              
            
!
999px

Console