I'm attempting to create a basic counter feature, where clicking on a button labelled "+" should increase a variable named Score
by 1, and the "-" button should decrease it by 1. However, I've encountered an issue where pressing the "+" button for the first time actually decreases the score by one before increasing it on the second click, and the same applies for the "-". Can anyone identify what I'm doing incorrectly here?
Just to note, I'm coding for enjoyment and am fairly new to Stack Overflow, so please excuse any messy code in my implementation.
<!DOCTYPE html>
<html>
<p id="Score1">
</p>
<p id="Score2">
</p>
<button type: button onclick= PlusOneTeam1()>
+
</button>
<button type: button onclick="MinusOneTeam1()">
-
</button>
<button type: button onclick="PlusOneTeam1">
+
</button>
<button type: button onclick="MinusOneTeam2">
-
</button>
<script>
var Score = 0
document.getElementById("Score1").innerHTML = Score
function PlusOneTeam1() {
document.getElementById("Score1").innerHTML = Score ++ ;
return Score ;
}
function MinusOneTeam1() {
document.getElementById("Score1").innerHTML = Score -- ;
}
</script>
</html>