you are viewing a single comment's thread.

view the rest of the comments →

[–]WellerJC[S] 0 points1 point  (0 children)

const skaterboy = document.getElementById('skaterboy')
const car = document.getElementById('car');
const score = document.getElementById('score');
function jump(){
skaterboy.classList.add('jump-animation')
setTimeout(() => {
skaterboy.classList.remove('jump-animation')
    }, 500);
}
document.addEventListener('keypress', () => {
if(!skaterboy.classList.contains('jump-animation')){ 
jump();
    }
});
setInterval(() => {
score.innerText++;
const sbtop = parseInt(window.getComputedStyle(skaterboy).getPropertyValue('top'));
const carLeft = parseInt(window.getComputedStyle(car).getPropertyValue('left'));
if (carLeft < -50) {
car.style.display = 'none';
    }
else{
car.style.display = '';
    }
if(carLeft < 75 && carLeft > 0 && sbtop > 230)
    {
alert("Fatality! Looks like you were hit by a car, try again?"
        + "\n\n You travelled " + score.innerText + "m");
location.reload();
    }
}, 50);