cannot read property "style" of undefined. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

cannot read property "style" of undefined.

So im trying to create a color memory game with JavaScript, the first step is to assign random colors to the cards when the player clicks on the start button, however i keep getting the error in the title whenever i click on the start button. https://code.sololearn.com/W8COEexfNGgb/?ref=app

18th May 2019, 11:08 PM
armin harper
1 Answer
+ 2
https://code.sololearn.com/WkwLtQ0sh27h/?ref=app The reason why you got that error was because javascript tried to run before the DOM was loaded, hence document.querySelector('button ') return undefined. To solve this issue, you have to tell javascript to wait until the DOM is loaded before executing. we do this by wrapping your entire code in a function called "onload" window.onload = () => { ...your code }
19th May 2019, 2:05 AM
Dlite
Dlite - avatar