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

              
                <div class="game-container">
  <h1 class="title">๐ŸŽ Gift Dash Challenge ๐ŸŽ</h1>
  <p class="instructions">Unwrap as many gifts as you can before time runs out! โœจ</p>
  <div class="score-timer">
    <span class="score">Score: <span id="score">0</span> ๐ŸŽฏ</span>
    <span class="timer">Time Left: <span id="timer">30</span>s โฑ๏ธ</span>
  </div>
  <div id="game-board" class="game-board"></div>
  <button id="start-button" class="start-button">๐ŸŽ… Start the Challenge</button>
  <p class="hint">๐ŸŽฎ Tip: Click fast and stay sharp, gifts wonโ€™t wait forever!</p>
</div>

              
            
!

CSS

              
                /* Global Styles */
body {
  font-family: 'Poppins', sans-serif;
  background: linear-gradient(135deg, #1e3c72, #2a5298);
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  color: #fff;
  overflow: hidden;
}

.game-container {
  text-align: center;
  max-width: 650px;
  width: 90%;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  padding: 30px;
  backdrop-filter: blur(10px);
  animation: fadeIn 1s ease-out;
}

/* Title and Instructions */
.title {
  font-size: 3rem;
  margin-bottom: 15px;
  background: linear-gradient(90deg, #ff9a9e, #fad0c4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: bold;
}

.instructions {
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: #e8e8e8;
  font-style: italic;
}

/* Score and Timer Section */
.score-timer {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 1.2rem;
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.score, .timer {
  background: linear-gradient(90deg, #fad0c4, #ff9a9e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Game Board */
.game-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  justify-items: center;
  margin: 20px 0;
  padding: 10px;
}

/* Gift Boxes */
.gift {
  width: 90px;
  height: 90px;
  background: linear-gradient(120deg, #f093fb, #f5576c);
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
  animation: bounce 1s infinite;
  transform-origin: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gift:hover {
  transform: scale(1.2) rotate(-5deg);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.gift::before {
  content: '๐ŸŽ';
  font-size: 2.5rem;
}

.explosion {
  position: absolute;
  font-size: 2.5rem;
  animation: pop 0.6s forwards;
}

/* Start Button */
.start-button {
  background: linear-gradient(120deg, #43cea2, #185a9d);
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  padding: 12px 25px;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.start-button:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

/* Hint Text */
.hint {
  font-size: 0.9rem;
  color: #d3d3d3;
  margin-top: 15px;
  font-style: italic;
}

/* Animations */
@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@keyframes pop {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.8);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.share-button {
  display: inline-block;
  margin-top: 20px;
  padding: 12px 20px;
  background: linear-gradient(120deg, #1da1f2, #0d8de0); /* Twitter blue gradient */
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  text-decoration: none;
  border-radius: 50px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  text-align: center;
}

.share-button:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  background: linear-gradient(120deg, #1a91da, #0a74bd); /* Slightly darker blue */
}

.share-button:active {
  transform: scale(0.95);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
}

              
            
!

JS

              
                const gameBoard = document.getElementById("game-board");
const startButton = document.getElementById("start-button");
const scoreDisplay = document.getElementById("score");
const timerDisplay = document.getElementById("timer");

let score = 0;
let timeLeft = 30;
let giftInterval;
let timerInterval;

// Creates a gift with random placement on the game board
function createGift() {
  const gift = document.createElement("div");
  gift.classList.add("gift");

  // Random position within the game board boundaries
  const posX = Math.random() * (gameBoard.clientWidth - 80);
  const posY = Math.random() * (gameBoard.clientHeight - 80);
  gift.style.transform = `translate(${posX}px, ${posY}px)`;

  // Add click event to unwrap the gift
  gift.addEventListener("click", () => {
    if (!gift.classList.contains("clicked")) {
      gift.classList.add("clicked");
      score++;
      scoreDisplay.textContent = score;

      // Add explosion effect
      const explosion = document.createElement("div");
      explosion.classList.add("explosion");
      explosion.textContent = "โœจ";
      gift.appendChild(explosion);

      // Remove the gift after the explosion animation
      setTimeout(() => gift.remove(), 600);
    }
  });

  // Append the gift to the game board
  gameBoard.appendChild(gift);

  // Automatically remove the gift if not clicked within 2 seconds
  setTimeout(() => {
    if (!gift.classList.contains("clicked")) {
      gift.remove();
    }
  }, 2000);
}

// Starts the game
function startGame() {
  resetGame();
  startButton.disabled = true;

  // Controls gift spawn rate and increases difficulty over time
  let spawnRate = 800;
  giftInterval = setInterval(() => {
    if (timeLeft > 0) {
      createGift();
      if (timeLeft % 10 === 0 && spawnRate > 400) {
        clearInterval(giftInterval);
        spawnRate -= 100; // Gifts spawn faster as time progresses
        giftInterval = setInterval(createGift, spawnRate);
      }
    }
  }, spawnRate);

  // Countdown timer
  timerInterval = setInterval(() => {
    if (timeLeft > 0) {
      timeLeft--;
      timerDisplay.textContent = timeLeft;
    } else {
      clearInterval(timerInterval);
      clearInterval(giftInterval);
      endGame();
    }
  }, 1000);
}

// Resets the game to its initial state
function resetGame() {
  score = 0;
  timeLeft = 30;
  scoreDisplay.textContent = score;
  timerDisplay.textContent = timeLeft;
  gameBoard.innerHTML = "";
}

// Ends the game and displays the final score with a share button
// Ends the game and displays the final score with a share button
function endGame() {
  startButton.disabled = false;
  const tweetText = encodeURIComponent(
    `๐ŸŽ I just scored ${score} points in the Gift Dash Challenge! ๐ŸŽ„โœจ Can you beat my score? Play now and spread the holiday cheer: https://codepen.io/HanGPIIIErr/pen/emOvJaz #GiftDash #HolidayFun #ChristmasGames`
  );
  const twitterShareUrl = `https://twitter.com/intent/tweet?text=${tweetText}`;

  gameBoard.innerHTML = `
    <div class="end-screen">
      <h2>๐ŸŽ‰ Game Over!</h2>
      <p>Your Final Score: <strong>${score}</strong></p>
      <button id="restart-button" class="start-button">๐Ÿ”„ Play Again</button>
      <a href="${twitterShareUrl}" target="_blank" class="share-button">๐ŸŽ… Share on Twitter</a>
    </div>
  `;

  const restartButton = document.getElementById("restart-button");
  restartButton.addEventListener("click", startGame);
}


// Event listener for the start button
startButton.addEventListener("click", startGame);

              
            
!
999px

Console