0

EROR When trying to wear ramdom ()

I want to change the color on each element P with Random Methods but an error can get helped me to fix this error? https://code.sololearn.com/WHg2K4jApQ52/?ref=app

18th Aug 2018, 3:38 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
5 Respuestas
+ 2
try using: Math.random()*255 instead of random(255)
18th Aug 2018, 4:04 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 3
In your JS section: window.onload = function(){ const texts = document.querySelectorAll(".container p"); let randomColors = function(){ let limit = texts.length; for(i = 0; i < limit; ++i) { texts[i].style.color = "rgb(" + Math.floor(Math.random()*256) + "," + Math.floor(Math.random()*256) + "," + Math.floor(Math.random()*256) + ")"; } } setInterval(randomColors,1500); }
18th Aug 2018, 4:20 PM
Ipang
+ 3
hafizd21j You're welcome : )
18th Aug 2018, 4:25 PM
Ipang
+ 1
thanks Ipang now I know the method is better than what I used before
18th Aug 2018, 4:23 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
+ 1
👍👍👍👍
18th Aug 2018, 4:29 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar