Game update div error

Hello. I somehow deleted my resultDiv variable in my game and can’t reference it anymore, apparently. I don’t know where I deleted it from so I’m looking for a fresh pair of eyes on this. Forgive me I’m not that good at de bugging my code yet.

Here is my updated/current game w/ the reference error.
Thank you.

Hello there,

We recommend familiarising yourself with how to ask a question on this forum. Specifically, you are more likely to get useful help, if you provide a helpful title and description:

Umm lol. I appreciate the help but I felt that I was super descriptive w/ the issue I’m having.

Open the console and look at the error it has a line number. Go to that line in the code and find the variable. It is inside a function, does that function have access to the variable in its own scope or an outer scope?

You even have some comments inside that function.

// You should do result.innerText = 'You Lose!'
// Don't forget to grab the div with the 'result' id!

This is how you use it inside the endGame function.

const resultDiv = document.getElementById('result')

After you fix that you have the same error with handsDiv and playerScoreDiv.

I would suggest you grab the DOM elements one time at the start of the code and just use the top-level variables throughout the code. There is really no reason to keep querying the DOM for the same elements.

I edited your post. Replit links get embedded and it fails (for whatever reason) so we don’t see the link at all. Try posting the Replit links inside code blocks so that doesn’t happen.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.