Guess-Game | It is a YES-OR-NO Guess Game | Game Engine library
kandi X-RAY | Guess-Game Summary
kandi X-RAY | Guess-Game Summary
It is a YES-OR-NO Guess Game.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Guess-Game
Guess-Game Key Features
Guess-Game Examples and Code Snippets
Community Discussions
Trending Discussions on Guess-Game
QUESTION
Please let me know if there is any additional information I can add to help make my problem more clear!
Im trying to get my hangman game to not allow another key press of the same kind if it is deemed to be incorrect. Once a key press is deemed incorrect it is shown on screen as an incorrect guess and I don't want it to be shown more than once or to count as another incorrect guess as guesses are limited. Here's a link to my site: https://thy-turk.github.io/Word-Guess-Game/
Here is the code I've been trying to manipulate to allow this.
...ANSWER
Answered 2019-Oct-20 at 05:42Ok, so I'm gonna put my edited version of your code at the bottom and do the explaining up here.
First, you needed somewhere to keep track of the letters that you had already pressed. I added an array at the top of your script section to keep everything together. This is also important because it is outside the scope of the keyup event
Second, I actually added a little quality of life change in there. You weren't checking if the button pressed was actually a letter so I fixed that by wrapping everything in an if statement and then checking for the letter codes.
Then finally all were doing is using the includes()
function. That's gonna check if the letter that was pressed has been seen already. If it has we do nothing. If it hasn't then we'll push that letter into the pastLetters array so that if we see it again we don't punish the user for it. Since the pastLetters array if in the parent scope of this it's persistent and won't be overridden if there's another keydown event.
Also important to note! I added that array to your reset pieces too so that when the game gets reset, the pastLetters array also gets reset.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Guess-Game
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page