diff --git a/public/script.js b/public/script.js index 0dd1b17..8f043d2 100644 --- a/public/script.js +++ b/public/script.js @@ -67,7 +67,7 @@ function updatePixel(index, color) { } // Function to update the pixel count display -function updatePixelCount() { +function updatePixelCount(totalPixelsPlaced) { const pixelCountElement = document.getElementById('pixel-count'); pixelCountElement.textContent = `Total Pixels: ${totalPixelsPlaced}, Your Pixels: ${yourPixelsPlaced}`; } @@ -94,7 +94,7 @@ canvasDiv.addEventListener('click', (event) => { // Increment yourPixelsPlaced when you place a pixel yourPixelsPlaced++; - updatePixelCount(); + updatePixelCount(totalPixelsPlaced); // Save yourPixelsPlaced value to the cookie setCookie('yourPixelsPlaced', yourPixelsPlaced, 365); // Cookie expires in 365 days } @@ -107,9 +107,8 @@ socket.on('updatePixel', (index, color) => { // Receive the total pixels count from the server socket.on('totalPixelsCount', (count) => { - totalPixelsPlaced = count; - updatePixelCount(); + updatePixelCount(count); }); createCanvas(); -updatePixelCount(); // Call to initialize the pixel count display +updatePixelCount(0); // Call to initialize the pixel count display with 0