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
1 Antwort
+ 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
}