keyCode not working, geting scratch on keyCode on using document.onkeyup or onkeydown, scratch will go when i use document.onclick, but i want onkeyup

Viewed 19
document.onkeyup = function(e){
console.log("Key code is:",e.keyCode)
if(e.keyCode == 38){
    dino=document.querySelector('.dino');
    dino.classList.add('animateDino');
    setTimeout(()=>{
        dino.classList.remove('amimateDino')
    },700);
  }
}

I'm doing a popular dino game tutorial from a youtube channel called code with harry, I'm struck with the initial stage itself
Image 1:this is my image with onkeyup Image 2:this is my image with onclick Image3: this is the image from where I'm learning:#CodeWithHarry here the code is showing normal but in my vs code(please open the above-linked photos to understand my problem), I'm getting a scratch on keyCode that scratch will go once if I use onclick or without anything that will be normal.

0 Answers
Related