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

218
Views
How to increment in javascript

let userScore = document.getElementById('userScore')
userScore = 0
if (whichOne == "rock" && compImg.src == imgArray[2].src) {
  console.log('win')
  userScore + 1
}
<h4>User:</h4>
<div id='userScore'> </div>

The increment does not work, I tried userscore++ also but no luck. The console.log does work though. Where is my problem?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to increment a number that's shown in a DIV, you have to first get that value into the userScore variable with .innerText. Then assign it back after adding 1.

let scoreDiv = document.getElementById('userScore')
let userScore = parseInt(scoreDiv.innerText);
if (whichOne == "rock" && compImg.src == imgArray[2].src) {
  console.log('win');
  scoreDiv.innerText = userScore + 1;
}
<h4>User:</h4>
<div id='userScore'>0</div>

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!