Logic for bring the words from Firebase done

This commit is contained in:
2021-10-14 22:12:30 -03:00
parent a7330c6804
commit d9f4948e53
9 changed files with 140 additions and 21 deletions

View File

@@ -14,8 +14,6 @@ const CheckVictory = (setIsVictory) => {
}
});
console.log(allChildrenHaveText)
if (allChildrenHaveText) {
setIsVictory(true)

View File

@@ -2,13 +2,11 @@ import CheckVictory from "./CheckVictory";
const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory, setIsDefeat) => {
const alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n", "ñ","o","p","q","r","s","t","u","v","w","x","y","z"];
const alphabet = ["a", "á", "b","c","d","e", "é", "f","g","h","i", "í", "j","k","l","m","n", "ñ","o", "ó","p","q","r","s","t","u","ú","v","w","x","y","z"];
const keyRegister = (event) => {
const currentKey = event.key.toLowerCase()
console.log(hangmanFrame)
if (hangmanFrame <= 5 && alphabet.includes(currentKey) ) {
@@ -18,8 +16,6 @@ const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory,
const letters = []
console.log(event.key)
if (actualWord.search(currentKey) + 1) {
for (let i = 0; i < actualWord.length; i++) {
@@ -53,6 +49,24 @@ const Register_Input = (actualWord, hangmanFrame, setHangmanFrame, setIsVictory,
setHangmanFrame(quantity)
if (hangmanFrame === 5) {
for (let i = 0; i < actualWord.length; i++) {
let letter = document.createElement('span')
letter.className = 'letter'
letter.textContent = actualWord[i]
if (i === 0) {
letter.textContent = letter.textContent.toUpperCase()
}
puzzleWord.replaceChild(letter, puzzleWord.children[i])
}
setIsDefeat(true)
}

View File

@@ -0,0 +1,11 @@
const SelectRandomWord = (arrayWords) => {
const randomWord = Math.trunc(
Math.random() * (arrayWords.length - 0) + 0
)
return randomWord
}
export default SelectRandomWord