I'm trying to make a simple counter, where clicking on a button named "+" should increase a variable (Score
) by 1 and button "-" should decrease it by 1. Thing is, whenever I press + the first time, Score
actually goes down by one before increasing on the second click, and vice versa with "-". What am I doing wrong?
By the way, I'm just coding for fun and am also new at Stack Overflow, so excuse the messy code.
<!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>