Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
incrementing HTML numbers with the DOM

I am working on a Rock Paper Scissors game and I am having some trouble incrementing the score when a win condition is met.

this is my HTML score that I want to increment

        <h1>you : <span id = "playerScore">0</span></h1>
let playersScore = document.getElementById('playerScore');
function playersChoosesRock(){
    if (playersChoice == ' Rock ' && computerChoice == ' Paper '){
        playersScore.innerHTML = ++;
        console.log('YOU LOSE');        
}

This is my javascript code the player selects Rock and the computer selects Paper I want to increment my 0 in the HTML if anyone can help it would be greatly appreciated.

This is the error that pops up when I attempt to make the innerHTML = '1'

Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You cant assign innerHtml to an operator because it takes a value.
You can add a counter in your JS and pass its value to innerHtml or innerText.

Check this example :

index.html

<h1>you <span id="playerScore">0</span></h1>
<button id="button">click</button>

app.js

let playerScore = document.getElementById("playerScore");
let button = document.getElementById("button");

let score = 0;

playerScore.innerHTML = score;

button.addEventListener("click", () => {
  score++;
  playerScore.innerHTML = score;
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda