Hangman
Implement (a simple variant of) the classic Hangman-game
- Place 26 green (
<button class="tertiary">
) buttons with the letters of the alphabet in#buttonDiv
TIP: Use/loop through the letters of the given stringalphabet
with thecharAt()
method - Generate a random number to choose a specific word out of the array
words
to play the game with
NOTE: Feel free to add additional words to the arraywords
- Place the chosen word in
#playDiv
by adding onespan
(with a non-breaking space) for every letter
NOTE: Thesespan
tags get some (default) styling (black bottom border, width, height, ...) via the given embedded CSS - Add an event listener to every button. When a button is clicked:
- It is disabled for future use
- Use a function
checkLetter(letter)
in which you check if the letter on the clicked button is present in the word- If so, this letter is shown in the corresponding
span
tag(s) in#playDiv
(and the border bottom of these tag(s) get the HTML colorgreen
). - If the letter is not present, the next hangman image (/assets/hangman/Hangman-x.png) is shown in the
img
in#scoreDiv
TIP: Use/declare a variable in which you store the number of wrong guesses so far to determine the correct hangman image
- If so, this letter is shown in the corresponding
- Use a function
checkStatus()
in which you check the status of the game after every round (button click):- If all letters are found, all buttons are disabled and the
figcaption
below the hangman image shows "YOU WON :-)"
TIP: Declare a variable in which you store the number of guessed letters, adjust it when necessary and compare it to the length of the word - If not all letters are found, you should check whether the game is over (after 6 wrong guesses). If so, all buttons are disabled and the
figcaption
below the hangman image now shows "YOU LOST :-)". The letters (and the corresponding bottom border) that are not found are shown in the HTML colorred
.
disableButtons()
andupdateFigcaption(text)
to make your code more structured and readable - If all letters are found, all buttons are disabled and the
REMARK: Use arrow functions where possible!