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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="card">

    <div class="instructions">
        <h1>Match 3 <span>💎</span> to win!</h1>
        <h2>Click the <span>💰</span> to reveal</h2>
    </div>

    <div class="emoji-container">
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
        <button class="emoji-btn"><span class="emoji-output"></span></button>
    </div>
</div>

<div class="dialog-box">
    <h2 class="dialog-message"></h2>
</div>

<audio src="https://www.freesfx.co.uk/rx2/mp3s/4/16298_1460570779.mp3" class="bell-sound-1"></audio>
<audio src="https://www.freesfx.co.uk/rx2/mp3s/4/16297_1460570779.mp3" class="bell-sound-2"></audio>
<audio src="https://www.freesfx.co.uk/rx2/mp3s/4/16296_1460570779.mp3" class="bell-sound-3"></audio>
<audio src="https://www.freesfx.co.uk/rx2/mp3s/4/16290_1460570777.mp3" class="win-sound"></audio>
<audio src="https://www.freesfx.co.uk/rx2/mp3s/4/16293_1460570778.mp3" class="lose-sound"></audio>
              
            
!

CSS

              
                /* 

Full-Page View:

https://codepen.io/GeorgePark/full/WgGmPq/

*/

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Open Sans', Arial, sans-serif;
    font-weight: 800;
    text-align: center;
    text-transform: uppercase;
    color: #fff;
    padding: 20px;
    overflow-x: hidden;
    background-image: linear-gradient(to bottom right, #92fe9d 0%, #00c9ff 100%);
}

.card {
    padding: 25px;
    border-radius: 20px;
    border: 3px solid #5b2361;
    background-color: #c066ff;
    background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23df8eff' fill-opacity='0.7' fill-rule='evenodd'%3E%3Cpath d='M0 40L40 0H20L0 20M40 40V20L20 40'/%3E%3C/g%3E%3C/svg%3E");
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}

.emoji-container {
    display: grid;
    grid-template-columns: repeat(3, auto);
    justify-content: center;
    border-radius: 20px;
    border: 3px solid #5b2361;
    overflow: hidden;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%23a3a3a3' fill-opacity='0.4' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E");
}

h1,
h2 {
    line-height: 1.2;
    -webkit-text-stroke-width: 2px;
    -webkit-text-stroke-color: #341238;
}

h1 span,
h2 span {
    -webkit-text-stroke-width: 0;
}

h1 {
    font-size: 40px;
    margin: 25px 0;
}

h2 {
    font-size: 28px;
    margin-bottom: 40px;
}

.emoji-btn {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 130px;
    height: 130px;
    font-size: 70px;
    border: none;
    padding: 0;
    background: none;
    outline: none;
    overflow: hidden;
    user-select: none;
    cursor: pointer;
    transition: transform 1s, background-color 2s;
}

.emoji-btn::after {
    content: '💰';
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    transition: transform 800ms;
}

.emoji-btn span {
    border-radius: 50%;
    transform: scale(0);
    transition: transform 800ms cubic-bezier(0.22, 0.64, 0.69, 1.3), background-color 3s, box-shadow 1.5s;
}

.uncovered::after {
    transform: rotate(-600deg) scale(0);
}

.uncovered span {
    transform: scale(1);
}

.winning-emoji span {
    background-color: rgba(255, 217, 0, 0.85);
    box-shadow: 0 0 10px 8px rgba(255, 217, 0, 0.85);
}

.dialog-box {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: -100px;
    left: 50%;
    width: 500px;
    height: 150px;
    font-weight: 600;
    border-radius: 25px;
    border: 3px solid #5b2361;
    background-image: linear-gradient(to right, #b465da, #cf6cc9 33%, #ee609c 66%, #ee609c);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    transform: translate(-50%, -50%);
}

.show-dialog {
    display: flex;
    animation: showDialog 1s 2s forwards cubic-bezier(0.17, 0.67, 0.63, 1.3);
}

.dialog-message {
    font-size: 35px;
    margin-bottom: 0;
}

.dollar-bill {
    position: absolute;
    bottom: 100%;
    font-size: 50px;
    user-select: none;
    animation: rainMoney 3s linear forwards;
}

.dollar-bill:nth-child(2n) {
    animation-delay: 100ms;
}

.dollar-bill:nth-child(3n) {
    animation-delay: 400ms;
}

.dollar-bill:nth-child(4n) {
    animation-delay: 800ms;
}

.dollar-bill:nth-child(5n) {
    animation-delay: 1.2s;
}

@keyframes showDialog {
    100% {
        top: 50%;
    }
}

@keyframes rainMoney {
    90% {
        opacity: 1;
    }
    
    100% {
        opacity: 0;
        bottom: 15px;
        transform: rotate(360deg);
    }
}

              
            
!

JS

              
                window.addEventListener("DOMContentLoaded", () => {

    const emojiContainer = document.querySelector('.emoji-container'),
          emojiOutput = document.querySelectorAll('.emoji-output'),
          dialogBox = document.querySelector('.dialog-box'),
          dialogMessage = document.querySelector('.dialog-message'),
          bellSound1 = document.querySelector('.bell-sound-1'),
          bellSound2 = document.querySelector('.bell-sound-2'),
          bellSound3 = document.querySelector('.bell-sound-3'),
          winSound = document.querySelector('.win-sound'),
          loseSound = document.querySelector('.lose-sound'),
          winner = Math.floor(Math.random() * 2),
          outputEmojis = a => emojiOutput.forEach((emoji, i) => emoji.textContent = a[i]),
          shuffleArray = a => {
              for (let i = a.length - 1; i > 0; i--) {
                  const j = Math.floor(Math.random() * (i + 1));
                  [a[i], a[j]] = [a[j], a[i]];
              }

              return a;
          },
          init = () => {
              if (winner) {
                  emojis.push('💎');
                  message = "Congratulations!";
              } else {
                  emojis.push('⌚');
                  message = "Thanks for playing.";
              }

              outputEmojis(shuffleArray(emojis));
          },
          rainMoney = () => {
              const w = window.innerWidth;

              //Create dollar bills
              for(i = 0; i < 70; i++) {
                  const dollar = document.createElement('div');

                  dollar.classList.add('dollar-bill');
                  dollar.textContent = '💵';
                  dollar.style.left = `${Math.floor(Math.random() * w)}px`;

                  document.body.appendChild(dollar)
              }
          };

    let emojis = ['👜', '🏆', '🍾', '🎁', '👑', '💍', '💎', '💎'],
        winningEmojisFound = 0,
        emojisRemaining = 9,
        message = '';

    emojiContainer.addEventListener('click', e => {

        const target = e.target;

        if (target.classList.contains('emoji-btn') && !target.classList.contains('uncovered')) {

            emojisRemaining--;

            target.classList.add('uncovered');

            //Check if winning emoji found
            if (target.textContent === '💎') {

                target.classList.add('winning-emoji');

                //Play winning emoji found sound effect
                switch (winningEmojisFound) {
                    case 0:
                        bellSound1.play();
                        break;
                    case 1:
                        bellSound2.play();
                        break;
                    case 2:
                        bellSound3.play();
                        break;
                }

                winningEmojisFound++;
            }

            //Check if all emojis revealed
            if(emojisRemaining === 0) {

                //Play sound effect
                setTimeout(() => {
                    if (winner) {
                        winSound.play();
                        setTimeout(() => rainMoney(), 1200);
                    } else {
                        loseSound.play();
                    }
                }, 1500);

                //Show dialog box
                dialogBox.classList.add('show-dialog');
                dialogMessage.textContent = message;
            }
        }
    });

    //Initialize game
    init();

});
              
            
!
999px

Console