Cannot read property 'textContent' of null

Hi, I’m trying to follow a tutorial on building a calculator, mainly to understand the logic for my own react/redux project. The tutorial is here I’m only to the “happy path” where the user hits a number key. What I’m trying to accomplish is to check if the display is 0,and if so, take the key pressed and put it in the display instead. Only working with a single digit for simplicity’s sake at the moment.

The issue I cannot solve is that it keeps showing an error with textContent, but only when i refer to the display element. When i tell it to get the textContent of a key it seems to work perfectly fine, but when I tell it to get what is on my display I run into this error. After much googling where I can’t make heads or tails of the responses on various stackoverflow or github posts, I’ve come to the forum for help. Can anyone tell me what’s going on?

the pen is below:

The variable display doesn’t seem to be declared anywhere, unless I’m missing it?

Should be line 39 of the JS. declared as a constant

hey @sbrevolution5

when using a querySelector on a class you need to add the dot so it knows its a class

const display = document.querySelector('.calculator__display')
1 Like

my bad… I was missing it :drooling_face:

1 Like

Thanks so much! its astounding how easy it is to miss a freakin’ dot… Appreciate the help!

1 Like