Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
How do I stop counting scores once a player has reached the max score?

Working on The Odin Project Rock-Paper-Scissors enhancement considering DOM manipulation. Been doing it for 3 days, re-worked it a few times, (current version was done via tutorial) and managed to stop the counter once a score of 5 is reached. But, both the computer and player side can still get to 5 points via clicking, even if the opponent has already reached 5pts.

How can I stop the counter for a player if the opponent reached the goal first?

Here's the code:

const SELECTIONS = [
    {
        name: "rock",
        beats: "scissors"
    },
    {
        name: "paper",
        beats: "rock"
    },
    {
        name: "scissors",
        beats: "paper"
    }
]
const yourScoreSpan = document.querySelector("[data-your-score]");
const computerScoreSpan = document.querySelector("[data-computer-score]");

//Player plays
choices.forEach(choice => {
    choice.addEventListener("click", e => {
        const selectionName = choice.dataset.choice;
        const selection = SELECTIONS.find(selection => selection.name === selectionName)
    
        makeSelection(selection)
    })
})


//Selecting R,P,S
function makeSelection(selection) {
    const computerSelection = randomSelection();
    const yourWinner = isWinner(selection, computerSelection);
    const computerWinner = isWinner(computerSelection, selection);
    

    
    if((yourWinner && (yourScoreSpan.innerText < 5) && (computerScoreSpan.innerText !== 5))) 
    incrementScore(yourScoreSpan);
    

    if(computerWinner && (computerScoreSpan.innerText < 5) && (yourScoreSpan.innerText !== 5)) incrementScore(computerScoreSpan);
}

//Incrementing Scores
function incrementScore(scoreSpan) {
    scoreSpan.innerText = parseInt(scoreSpan.innerText) + 1
}


//Computer plays
function randomSelection() {
    const randomIndex = Math.floor(Math.random() * SELECTIONS.length);
    return SELECTIONS[randomIndex];
}

//Who wins
function isWinner(selection, opponentSelection) {
    return selection.beats === opponentSelection.name
}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda