-1

Why did " this " work in the first code and the second did not?

The first document.getElementById("bt").addEventListener("click",function(){ this.style.backgroundColor ="red"; let color=document.body.style setInterval(()=>{ color.backgroundColor =random_rgb() ; },200) }) function random_rgb() { returnrgb(${255Math.random()},${255Math.random()},${255*Math.random()}); }

The second code

`document.getElementById("bt").addEventListener("click",()=>{
   this.style.backgroundColor ="red"
   let color=document.body.style
   setInterval(()=>{
    color.backgroundColor =random_rgb() ;
},200)
  })

function random_rgb() { return rgb(${255*Math.random()},${255*Math.random()},${255*Math.random()}); }`

I tried writing the function in a traditional way and it worked, but in short, it did not work

0 Answers0