Is there a way to make my scoreboard increase by +1 point instead of +10?
In my JavaScript code, I used intervals as it was the only solution that worked:
let scoreInterval = setInterval(updateScore);
let score = 0;
function updateScore() {
var points = document.getElementById('score');
points.innerHTML = "Score: " + score++;
clearInterval(scoreInterval);
}
const gameLoop = setInterval(() => {
const pipePosition = pipe.offsetLeft;
const marioPosition = +window
.getComputedStyle(mario)
.bottom.replace("px", "")
if (pipePosition <= 120 && pipePosition > 0 && marioPosition < 80) {
pipe.style.animation = "none";
pipe.style.left = `${pipePosition}px`;
mario.style.animation = "none";
mario.style.bottom = `${marioPosition}px`;
mario.src = "./images/mario-game-over.png";
mario.style.width = "75px";
mario.style.marginLeft = "45px";
clearInterval(gameLoop);
} else if (pipePosition <= 0 && marioPosition >= 0) {
updateScore();
};
}, 10);
<div class="game">
<div id="score"></div>
</div>
Check out the webpage here: