+ 1

Can someone please check my javascript code? It is not working and I canā€™t figure out why..

This is my code: https://code.sololearn.com/WLbRocg4KTJp/?ref=app

3rd Nov 2018, 8:22 PM
Brian Bawuah
Brian Bawuah - avatar
2 Answers
+ 7
Brian Bawuah, The reason why your code acts like that is because the DOM is executed before the JavaScript. You need to make sure the JavaScript executes before the DOM. Therefore you need to add window.onload event. Second is you did not wrote the event listener correct. It is addEventListener instead of eventListener. Have a look at the changes, hope it helpsšŸ‘ https://code.sololearn.com/WaeCNY58Y56Z/?ref=app
3rd Nov 2018, 8:29 PM
šŸŒ“Vincent BergeršŸŒ“
šŸŒ“Vincent BergeršŸŒ“ - avatar
+ 2
It's easier to define the function by onclick keyword: <button onclick="myfunc()">
3rd Nov 2018, 8:45 PM
ŠœŠøŠŗŠ¾Š»Š° Š¤ŠµŠ“Š¾ŃŃ”Ń”Š²
ŠœŠøŠŗŠ¾Š»Š° Š¤ŠµŠ“Š¾ŃŃ”Ń”Š² - avatar