From ec553dd513d63410225b86a6bb86f47ea5dcc320 Mon Sep 17 00:00:00 2001 From: ElektricM Date: Fri, 21 Jul 2023 21:24:44 +0200 Subject: [PATCH] updated script.js to fix totalPixelsPlaced is not defined error --- public/script.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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