Skip to content

Commit

Permalink
Create Eggscript.js
Browse files Browse the repository at this point in the history
  • Loading branch information
emily202777 authored Oct 24, 2024
1 parent ea9ad0c commit 823e30d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Eggscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// JavaScript file: Eggscript.js

let clickCount = 0; // To track the number of clicks

// Select the image by its ID
const eggImage = document.getElementById('eggImage');

// Add an event listener to track clicks on the image
eggImage.addEventListener('click', function () {
clickCount++; // Increment the click count

// First transition: After 3 clicks, change the image to crackingEgg.png
if (clickCount === 3) {
eggImage.src = 'crackingEgg.png'; // Change the image to the cracking egg
}

// Second transition: After 8 total clicks, change the image to fullyCracked.png and remove other elements
if (clickCount === 8) {
eggImage.src = 'fullyCracked.png'; // Change the image to the fully cracked egg

// Hide the existing button (if present)
const buttonContainer = document.querySelector('.button-container');
if (buttonContainer) {
buttonContainer.style.display = 'none'; // Hide the previous button
}

// Add a new button on top of the fully cracked image
addFullyCrackedButton(); // Call function to add the new button
}
});

// Function to add the new button after the image changes to fully cracked
function addFullyCrackedButton() {
const newButtonContainer = document.createElement('div');
newButtonContainer.classList.add('button-container');

// Create the button element
const newButton = document.createElement('button');
newButton.classList.add('btn');
newButton.textContent = 'Continue to Next Module'; // Button text
newButton.onclick = function () {
location.href = 'twoModulesUnlocked.html'; // Redirect to the next page
};

// Add the button to the button container
newButtonContainer.appendChild(newButton);

// Append the button container to the main header or body
const header = document.querySelector('header');
header.appendChild(newButtonContainer);
}

0 comments on commit 823e30d

Please sign in to comment.