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?
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>