在下面的代码中,如果玩家猜测某个字母不在所选的密码中,我就无法执行代码。我把它设置为当提交按钮被击中时,我们首先检查猜测字母是否在拼图中,如果是字母被翻过来,那么我想说是否不在单词中远离玩家的生活。我已经尝试了几种方法,但无法使程序正确读取第二个if语句。
submit.addEventListener('click', function(){
console.log("clicked");
usedLetters.innerHTML += playersLetter.value + ' '
for(i=0; i<checkWord.length; i++){
console.log(wordLife)
if(playersLetter.value == (checkWord[i])){
console.log('in if#1')
console.log(playersLetter.value)
var answerLetter = document.getElementsByClassName('letter')[i]
answerLetter.innerHTML = playersLetter.value
wordLife--
}
}
function scoreLetter(value){// To check if the letter is actually in the word
for(let i = 0; i < checkWord.length; i++){
if(value == (checkWord[i])){
return true
}else {
return false
}
}
}
console.log('read function')
if(scoreLetter(playersLetter.value) == false){
console.log('in 2nd if')
playerLife--
console.log(playerLife)
}
})