sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Game project issue #213

Closed da1dude closed 11 months ago

da1dude commented 11 months ago

What's the problem you're trying to solve?

1 - handling multiple letters 2 - ideas on how to properly reset the game 3 - you asked me to get ahold of you about ideas for better rending the spaceShip

Post any code you think might be relevant (one fenced block per file)

function handleChoice(evt) {
    evt.preventDefault();
    //hidden word array split by letter so we can compare them to the guessed letter
    const hiddenWordArray = hiddenWord.split("");
    console.log("this is the hidden word array", hiddenWordArray)
    //capturing the user guess and making it upper case
    let userGuess = document.getElementById("guess").value.toUpperCase()
    console.log("this is the userGuessed letter: ", userGuess)

    if (hiddenWordArray.includes(userGuess)) {
        console.log('guess is in word!!!')
        console.log('letter index', hiddenWordArray.indexOf(userGuess))
        //assigning correctGuessIndex to the index of hiddenwordarray(userGuess)
            //if user guess is correct assigning it the index of the guess
        const correctGuessIndex = hiddenWordArray.indexOf(userGuess)
        const letterSpace = document.getElementById(`space-${correctGuessIndex}`)
        letterSpace.innerText=userGuess
        // use above //
    } else {
        wrongGuesses += 1
        console.log("current wrong guesses: ", wrongGuesses)
    } 
    //updating the guessedLetters array
    guessedLetters.push(userGuess)
    console.log("guessed letter aray: ", guessedLetters)
    //updating the guesses element with the guessedLetters array
    guessesEl.innerText=guessedLetters
    renderShip()
    winner()
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

What is your best guess as to the source of the problem?

Im guessing here but I think forEach needs to come into play to grab the other duplicate letter. Im just clueless on how to implement that (refactoring is hard)

What things have you already tried to solve the problem?

I tried several array methods attempting to experiment.

Paste a link to your repository here

https://github.com/da1dude/spaceman/tree/main

timmshinbone commented 11 months ago

I'm not sure I'm understanding what it is you're trying to solve here, can you give me a brief explanation of what exact part of this issue this pertains to?

da1dude commented 11 months ago

if a word like BUZZED has two letters I cannot get it to render the second letter.

timmshinbone commented 11 months ago

Ohhh right, I remember now. Will analyze right when I'm back from lunch and get back to ya.

timmshinbone commented 11 months ago

Check out the answer in this stackOverflow, see if that function makes sense and try to implement something similar that suits your needs. Let me know once you've looked it over and/or tried something similar

da1dude commented 11 months ago

Ive looked it over and am not really sure what I would need to change / modify in my code to implement determining if there was a duplicate and snagging that index to render it.

timmshinbone commented 11 months ago

ok we can look in a breakout room soon, I'll slack ya

da1dude commented 11 months ago

ok