Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Someone Help me I'm pretty confuse

<!DOCTYPE html> <html lang="en"> <head> <title>Score keeper</title> <style> .winner { color: green; } </style> </head> <body>

<h1><span id="p1Display">0</span> to <span id="p2Display">0</span></h1>
<p>Player to: 5</p>

<input type="number">
<button id="p1">Player One</button>
<button id="p2">Player two</button>
<button>Reset</button>

<script> var p1Button = document.querySelector("#p1"); var p2Button = document.querySelector("#p2"); var p1Display = document.querySelector("#p1Display"); var p2Display = document.querySelector("#p2Display"); var p1Score = 0; var p2Score = 0; var gameOver = false; var winningScore = 5;

p1Button.addEventListener("click", function(){
    if (!gameOver) {
        p1Score++;
        if (p1Score === winningScore ) {
            p1Display.classList.add("winner");
            gameOver = true;
        }
        p1Display.textContent = p1Score;
    }
});

p2Button.addEventListener("click", function(){
    if ( !gameOver ) {
        p2Score++;
        if ( p2Score === winningScore  ) {
            p2Display.classList.add("winner");
            gameOver = true;
        }

        p2Display.textContent = p2Score;
    }
});

</script> </body> </html>

There are code why var gameOver = false; this code p1Button is true why disable p2Button now work. Please describe your opinion actually i don't understand .