updated script.js to fix totalPixelsPlaced is not defined error

This commit is contained in:
ElektricM 2023-07-21 21:24:44 +02:00
commit ec553dd513

View file

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