0
Background color randomizer
Why isn't this working? https://code.sololearn.com/W45K5UiBVb14/#js
9 ответов
+ 2
You can't name function as bgColor.
https://code.sololearn.com/WSGd49FaKxEm/?ref=app
One other thing to note:
You shouldn't use onclick. always use addEventlistener()
https://www.sololearn.com/learn/JavaScript/2758/
edit: NIk01 I have changed everything. works fine
+ 2
See schindlabua's comment in second page of lesson
"Please, never use "<... onclick='...'>" or "x.onclick = ...". The proper way to do this (since the year 2000!) is
var x = document.getElementById('demo');
x.addEventListener('click', function(){
document.body.innerHTML = Date();
});
as mentioned later in the tutorial."
+ 2
I found this one. And read many answers.
https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick
Pros and cons both.
There isn't a problem in such small projects.
+ 2
Roneel thank you very much for the link. I’ve just learned how to attach more then 1 function to the same event :D. But I still will use onclick, when I need just one event handler )))
+ 1
Jack Rehfeldt your array consists of just 1 string :D I saw it just now, you should write like this:
[“red”, “blue”, “green”, etc...
+ 1
Roneel why ? whats the difference between writing onclick in html and adding an event in js ?
+ 1
I’ve read the comment and all the replies and still can’t get it. He didn’t say the reason he just says don’t use it, because don’t use it...
+ 1
Jack Rehfeldt Did your problem solve ?