<div class="game-container">
  <h1>Clicker Game</h1>
  <p>Score: <span id="score">0</span></p>
  <button id="click-button">Click Me!</button>
  <button id="upgrade-button" class="hidden">Upgrade Speed (Cost: <span id="upgrade-cost">10</span>)</button>
</div>
/* Cool gradient background */
body {
  font-family: 'Arial', sans-serif;
  background: linear-gradient(135deg, #1e3c72, #2a5298);
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  color: #fff;
}

/* Game container with glassmorphism effect */
.game-container {
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  padding: 30px;
  border-radius: 15px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Stylish title */
h1 {
  font-size: 2.5rem;
  margin-bottom: 20px;
  font-family: 'Orbitron', sans-serif;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* Score text */
#score {
  font-size: 1.8rem;
  font-weight: bold;
  color: #ffdd57;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* Buttons with hover effects */
button {
  padding: 12px 24px;
  font-size: 1.1rem;
  background-color: #ff6f61;
  color: #fff;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  margin: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

button:hover {
  background-color: #ff3b2f;
  transform: scale(1.05);
}

button:active {
  transform: scale(0.95);
}

/* Hidden class for the upgrade button */
.hidden {
  display: none;
}

/* Add a cool font for the title */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@700&display=swap');
let score = 0;
let clickValue = 1; // Points added per click
let upgradeCost = 10; // Initial upgrade cost

const scoreElement = document.getElementById("score");
const clickButton = document.getElementById("click-button");
const upgradeButton = document.getElementById("upgrade-button");
const upgradeCostElement = document.getElementById("upgrade-cost");

// Function to update the score display
function updateScore() {
  scoreElement.textContent = score;
}

// Function to update the upgrade cost display
function updateUpgradeCost() {
  upgradeCostElement.textContent = upgradeCost;
}

// Function to handle clicking the main button
clickButton.addEventListener("click", () => {
  score += clickValue; // Add points based on clickValue
  updateScore();

  // Show the upgrade button if the score reaches the upgrade cost
  if (score >= upgradeCost) {
    upgradeButton.classList.remove("hidden");
  }
});

// Function to handle upgrading
upgradeButton.addEventListener("click", () => {
  if (score >= upgradeCost) {
    score -= upgradeCost; // Deduct the upgrade cost
    clickValue += 1; // Increase points per click
    upgradeCost *= 2; // Double the upgrade cost for the next upgrade
    updateScore();
    updateUpgradeCost();

    // Hide the upgrade button if the player can't afford the next upgrade
    if (score < upgradeCost) {
      upgradeButton.classList.add("hidden");
    }

    alert(`Upgraded! Now you earn ${clickValue} points per click.`);
  } else {
    alert("Not enough points to upgrade!");
  }
});

// Initialize the upgrade cost display
updateUpgradeCost();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.