Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!