updated script.js to fix totalPixelsPlaced is not defined error
This commit is contained in:
parent
93bacdc100
commit
ec553dd513
1 changed files with 4 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue