+ 1

I have been stuck on this question can anyone help me?

var s = document. getElementsByTagName("span"); for(var x=0; x<s.length;x++) { s[_].style.backgroundColor = "#33EA73"; }

16th Mar 2019, 5:01 PM
Luke
Luke - avatar
3 odpowiedzi
+ 1
Just replace s[_] with s[x] One tips : actually it's a bad practice to compute length on every iteration Better idea is to cache it. Find below the code snippet for for-loop for(var x = 0, l = s.length; x < l; x = x + 1){ s[x].style.backgroundColor = "#33EA73"; }
16th Mar 2019, 5:15 PM
Rishi Anand
Rishi Anand - avatar
0
Never mind i just figured it out
16th Mar 2019, 5:09 PM
Luke
Luke - avatar
0
Ok
16th Mar 2019, 5:17 PM
Luke
Luke - avatar