
const timerInterval = setInterval(() => {
timeLeft -= 1;
timerElement.textContent = timeLeft;
if (timeLeft <= 0) {
clearInterval(timerInterval);
alert(`Time’s up! Final Score: Money – $${money}, Energy – ${energy} MW`);
}
}, 1000);
document.querySelectorAll(‘.energy-source’).forEach(source => {
source.addEventListener(‘click’, () => {
const cost = parseInt(source.getAttribute(‘data-cost’));
const energyGain = parseInt(source.getAttribute(‘data-energy’));
if (money >= cost) {
money -= cost;
energy += energyGain;
}
});
});
Features
How to Customize
<div class=”energy-source” data-cost=”150″ data-energy=”75″>
<img src=”images/geothermal-plant.png” alt=”Geothermal Plant”>
<span>Geothermal Plant</span>
<span>Cost: $150</span>
<span>Energy: 75 MW</span>
</div>
let timeLeft = 180; // 3 minutes instead of 2
money += Math.floor(energy / 5); // Earn $1 for every 5 MW
Step 1: Prepare New Images
Step 2: Place Images in the images Folder
Step 3: Update the HTML
<img src=”images/solar-panel.png” alt=”Solar Panel”>
<img src=”images/geothermal-plant.png” alt=”Geothermal Plant”>
Step 4: Update Labels
<span>Geothermal Plant</span>
<span>Cost: $150</span>
<span>Energy: 75 MW</span>
Step 1: Add New Energy Sources
<div class=”energy-source” data-cost=”150″ data-energy=”75″>
<img src=”images/geothermal-plant.png” alt=”Geothermal Plant”>
<span>Geothermal Plant</span>
<span>Cost: $150</span>
<span>Energy: 75 MW</span>
</div>
Step 2: Adjust Costs and Energy Output
<div class=”energy-source” data-cost=”300″ data-energy=”120″>
Step 1: Replace the Background
.game-container {
background: url(‘images/eco-background.jpg’) no-repeat center center/cover;
}
Step 2: Change Color Scheme
body {
background-color: #e8f5e9; /* Light green */
}
h1 {
color: #1b5e20; /* Dark green */
}
Step 1: Change Timer Duration
let timeLeft = 180; // Change to 180 seconds for a longer game
Step 2: Alter Income Formula
money += Math.floor(energy / 5); // Earn $1 for every 5 MW instead of 10 MW
Step 3: Set a Win Condition
if (energy >= 500) {
clearInterval(timerInterval);
clearInterval(incomeInterval);
alert(‘You win! Clean energy goal achieved!’);
}
Feature 1: Add Negative Events
setInterval(() => {
if (Math.random() < 0.2) { // 20% chance
energy -= 10; // Lose 10 MW of energy
alert(‘Storm damage! Energy production reduced.’);
energyElement.textContent = energy;
}
}, 10000); // Check every 10 seconds
Feature 2: Progress Bar
Add a visual progress bar for the energy goal:
<div class=”progress-bar”>
<div id=”progress” style=”width: 0%; height: 20px; background-color: green;”></div>
</div>
function updateProgress() {
const percentage = (energy / 500) * 100;
document.getElementById(‘progress’).style.width = `${percentage}%`;
}