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

              
                <!-- Please like <3 and share if you enjoyed! -->


<div class="container" onclick="startSpin()">
  <h1 class="title"> Smiley Sl😱ts </h1>
  <div class="money-container">
    <div id="money">100</div>
    <div class="changes"> </div>
  </div>

  <div class="play-area">
    <div class="reel-container"></div>
    <div class="reel-container"></div>
    <div class="reel-container"></div>
  </div>

  <div class="info">
    <div class="instructions">
      Press anywhere to spin the reels.<br/> Each spin costs 1 💰<br/> Match at least two on the middle row to win!<br/> See prizes below.</div>

    <div class="prize-table">
      <div class="doubles">
      </div>
      <div class="triples">

      </div>
    </div>
              
            
!

CSS

              
                // Please like <3 and share if you enjoyed!

$borderCol: #1e1e1e;
$light2: #b3d5eb;
$light1: #edfaf9;
$med: #72c0c3;
$textCol: lighten($light1, 10%);
body {
  margin: 0;
  background: $med;
  user-select: none;
  cursor: pointer;
}
.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-items: center;
  justify-content: center;

  .title {
    font-family: "Fredoka One", cursive;
    font-size: 3rem;
    color: $textCol;
    text-decoration: underline;
  }

  .money-container {
    position: relative;
    margin-bottom: 0.5rem;
    font-family: "Roboto", sans-serif;
    color: $textCol;
    .changes {
      position: absolute;
      display: inline-flex;
      top: 1rem;
      font-weight: bold;
      .change {
        color: #044600;
        padding-left: 0.5rem;
        animation-duration: 1s;
        animation-name: slideinLeft;
        animation-fill-mode: forwards;
        &.negative {
          color: #860000;
        }
        @for $i from 1 through 8 {
          &:nth-child(#{$i}) {
            opacity: 1 - ($i*0.15);
          }
        }
      }
    }
    #money {
      font-size: 2rem;
      display: inline;
      margin-left: -8rem;
      font-weight: bold;
      &:before {
        content: "💰 ";
      }
    }
  }
  .play-area {
    position: relative;
    display: flex;
    background-image: linear-gradient(
      45deg,
      $light1 18.75%,
      $light2 18.75%,
      $light2 50%,
      $light1 50%,
      $light1 68.75%,
      $light2 68.75%,
      $light2 100%
    );
    background-size: 56.57px 56.57px;
    min-height: 12.5rem;
    border: solid $borderCol 5px;
    .reel-container {
      user-select: none;
      display: flex;
      justify-content: center;
      flex-direction: column;
      height: 12.5rem;
      overflow: hidden;
      align-items: center;
      width: 4rem;
      padding-left: 1rem;
      padding-right: 1rem;
      &:first-child {
        border-right: solid $borderCol 3px;
      }

      &:last-child {
        border-left: solid $borderCol 3px;
      }

      .reel-item {
        font-size: 3rem;
        animation-duration: 0.1s;
        animation-name: slidein;

        &.deactivate {
          animation-duration: 0.1s;
          animation-name: slideOut;
          animation-fill-mode: forwards;
        }

        &.win {
          animation: winFlashReels 1s infinite;
          border-radius: 50%;
        }
      }
    }
    &:before {
      position: absolute;
      content: "";
      width: 0;
      height: 0;
      top: calc(50% - 8px);
      border-top: 10px solid transparent;
      border-bottom: 10px solid transparent;
      border-left: 15px solid $borderCol;
    }

    &:after {
      position: absolute;
      content: "";
      width: 0;
      height: 0;
      right: 0;
      top: calc(50% - 8px);
      border-top: 10px solid transparent;
      border-bottom: 10px solid transparent;
      border-right: 15px solid $borderCol;
    }
  }

  .info {
    padding-top: 1rem;
    padding-bottom: 3rem;
    .instructions {
      color: $textCol;
      margin-bottom: 1rem;
      width: 500px;
      text-align: center;
      font-family: "Fredoka One", cursive;
    }

    .prize-table {
      width: 320px;
      margin-left: auto;
      margin-right: auto;
      display: flex;
      justify-content: space-between;
      color: $textCol;
      font-weight: bold;
      font-family: "Roboto", sans-serif;
      font-size: 1.3rem;
      .doubles {
        padding-right: 2rem;
      }
      .prize-item {
        opacity: 0.4;
        margin-bottom: 0.2rem;

        &.active {
          opacity: 1;
          animation: winFlashPrizeTable 1s infinite;
        }
      }
    }
  }
}
@keyframes slidein {
  from {
    font-size: 0.1rem;
    opacity: 0;
  }

  to {
    font-size: 3rem;
    opacity: 1;
  }
}

@keyframes slideOut {
  to {
    height: 0;
    font-size: 0.1rem;
    opacity: 0;
  }

  from {
    height: 3rem;
    font-size: 3rem;
    opacity: 1;
  }
}

@keyframes winFlashReels {
  0% {
    background-color: rgba(240, 240, 240, 0.2);
  }

  50% {
    background-color: rgba(20, 200, 20, 1);
  }
  100% {
    background-color: rgba(240, 240, 240, 0.2);
  }
}

@keyframes winFlashPrizeTable {
  0% {
    opacity: 0.2;
  }

  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
  }
}

@keyframes slideinLeft {
  to {
    font-size: 1rem;
  }

  from {
    font-size: 0rem;
  }
}

              
            
!

JS

              
                // Please like <3 and share if you enjoyed!

let reelContents = ["😂", "😍", "😅", "🤔", "😜", "🤐", "😱", "😵"];
let reelLength = 3;
let reelContainers = document.querySelectorAll(".reel-container");
let spinningReels = [];
let spinning = false;
let reelDelay = 100;

let money = 100;
let moneyToAdd = 0;

let audioCtx = new (window.AudioContext || window.webkitAudioContext)();

let masterVolume = audioCtx.createGain();
masterVolume.gain.setValueAtTime(0.05, audioCtx.currentTime);
masterVolume.connect(audioCtx.destination);

let getReelItem = () => {
  let newReel = document.createElement("div");
  newReel.innerHTML =
    reelContents[Math.floor(Math.random() * reelContents.length)];
  newReel.classList.add("reel-item");
  setTimeout(() => {
    newReel.classList.add("active");
  }, 0);

  return newReel;
};

let startSpin = () => {
  if (!spinning && money > 0) {
    document.querySelectorAll(".prize-item.active").forEach(s => {
      s.classList.remove("active");
    });
    updateMoney(-1);
    setChange(-1);
    spinningReels.push(0);
    setTimeout(() => {
      spinningReels.push(1);
    }, reelDelay);
    setTimeout(() => {
      spinningReels.push(2);
    }, reelDelay * 2);

    spinning = true;
    spinUpdate(7);
  }
};

let spinUpdate = spinsLeft => {
  spinningReels.forEach(n => {
    moveReel(n);
  });
  if (spinsLeft > 0) {
    setTimeout(() => {
      spinUpdate(spinsLeft - 1);
    }, reelDelay);
  } else {
    if (spinningReels.length > 0) {
      spinningReels.shift();

      setTimeout(() => {
        spinUpdate(0);
      }, reelDelay);
      playNote(160 - (30 - spinningReels.length * 10), 0.1);
    } else {
      spinning = false;
      findWins();
    }
  }
};

let moveReel = reelIndex => {
  let selectedReel = reelContainers[reelIndex];
  selectedReel.prepend(getReelItem());
  if (selectedReel.children.length > reelLength) {
    selectedReel.lastElementChild.classList.add("deactivate");
    setTimeout(() => {
      selectedReel.removeChild(selectedReel.lastElementChild);
    }, reelDelay);
  }
};

let updateMoney = change => {
  money += change;
  document.querySelector("#money").innerText = money;
};

let setChange = change => {
  let changes = document.querySelector(".changes");
  let newChange = document.createElement("div");
  newChange.innerHTML = change > 0 ? `+${change}` : change;
  newChange.classList.add("change");
  if (change < 0) newChange.classList.add("negative");
  changes.prepend(newChange);
  if (changes.children.length > 6) {
    changes.removeChild(changes.lastElementChild);
  }
};

let playWinChime = amount => {
  let clampedAm = amount > 20 ? 20 : amount;
  playNote(400 + 100 * (20 - clampedAm), 0.05, "sine");
  if (--amount > 0)
    setTimeout(() => {
      playWinChime(amount);
    }, 70);
};

let findWins = () => {
  let winline = [];
  let symbols = {};
  reelContainers.forEach(reel => {
    let symbol = reel.children[1].innerText;
    winline.push(symbol);
    if (symbols[symbol]) symbols[symbol]++;
    else symbols[symbol] = 1;
  });

  if (
    winline.filter(s => {
      return s === winline[0];
    }).length === 3
  ) {
    win(3, winline[0]);
    document
      .querySelector(".triples")
      .children[reelContents.indexOf(winline[0])].classList.add("active");
  } else {
    for (s in symbols) {
      if (symbols[s] == 2) {
        win(2, s);
        document
          .querySelector(".doubles")
          .children[reelContents.indexOf(s)].classList.add("active");
      }
    }
  }
};

let win = (amountMatching, symbol) => {
  reelContainers.forEach(reel => {
    if (reel.children[1].innerText === symbol)
      reel.children[1].classList.add("win");
  });
  let winAmount = 1 + reelContents.indexOf(symbol);
  playWinChime(winAmount);
  if (amountMatching == 3) winAmount *= 100;

  setChange(winAmount);
  addToMoney(winAmount);
};

let addToMoney = (amount, speed) => {
  let changeAmount = Math.ceil(amount / 2);
  updateMoney(changeAmount);
  let remainder = amount - changeAmount;
  if (!speed) speed = 101;
  speed -= 5;
  if (speed < 10) speed = 10;
  if (remainder)
    setTimeout(() => {
      addToMoney(remainder);
    }, speed);
};

function playNote(freq, dur, type) {
  if (!freq) freq = 1000;
  if (!dur) dur = 1;
  if (!type) type = "square";
  return new Promise(res => {
    let oscillator = audioCtx.createOscillator();
    oscillator.type = type;
    oscillator.frequency.setValueAtTime(freq, audioCtx.currentTime); // value in hertz
    oscillator.connect(masterVolume);
    oscillator.start();
    oscillator.stop(audioCtx.currentTime + dur);
    oscillator.onended = res;
  });
}

//fills reels
reelContainers.forEach((reel, i) => {
  for (let n = 0; n < reelLength; n++) {
    moveReel(i);
  }
});

let addToPrizeTable = (combo, amount, target) => {
  let pt = document.querySelector(`.prize-table .${target}`);
  let prize = document.createElement("div");
  prize.innerHTML = `${combo}: ${amount}`;
  prize.classList.add("prize-item");
  prize.setAttribute("win-attr", combo.replace(/[-❔]/g, ""));
  pt.append(prize);
};

//fill prize table
reelContents.forEach((symbol, index) => {
  addToPrizeTable(`${symbol}-${symbol}-❔`, index + 1, "doubles");
});

reelContents.forEach((symbol, index) => {
  addToPrizeTable(
    `${symbol}-${symbol}-${symbol}`,
    (index + 1) * 100,
    "triples"
  );
});

              
            
!
999px

Console