gpt4 book ai didi

javascript - 为什么我的文本更新函数不显示文本?

转载 作者:行者123 更新时间:2023-11-27 23:09:21 25 4
gpt4 key购买 nike

为什么我的textUpdated()功能不工作?

我想在容器 ( <div id = 'textUpdate'> ) 下显示文本,但没有显示任何内容。

如果您想查看完整代码:https://repl.it/@securethebags/theBeatles-quiz

运行它: https://thebeatles-quiz.securethebags.repl.co/

我试过改变我的 if-else-if 背后的逻辑声明,但这没有用。我还检查以确保我所有的 var 名称都是正确的:

function selectAnswer(e){  //called when an answer button is pressed
clearStatusClass(document.body)
const selectedButton = e.target;
const correct = selectedButton.dataset.correct
Array.from(answerButtonsElement.children).forEach(button =>{
setStatusClass(button, button.dataset.correct) // change
background for each button if answer is correct/wrong
})
if(shuffledQuestions.length > currentQuestionIndex + 1){
nextButton.classList.remove('hide')
}
else{
startButton.innerText = "Restart"
startButton.classList.remove('hide')
}
updateScore(correct);
textUpdatd()
}

function textUpdatd(){
textUpdate.classList.remove('hide')
if(scoreboard.right == questions.length)
textUpdate.innerText = "WOW you got them all right! Groovy!"
else if(scoreboard.wrong == questions.length)
textUpdate.innerText = "WOW you got them all wrong! Gnarly!"
else if(scoreboard.right > scoreboard.wrong)
textUpdate.innerText = "Not bad! - You must know your stuff!"
else if(scoreboard.wrong > scoreboard.right )
textUpdate.innerText = "Not doing too hot! Better luck next time!"
else if(scoreboard.wrong == scoreboard.right && scoreboard.right != 0 || scoreboard.wrong != 0)
textUpdate.innerText = "You are currently tied with right and wrong answers!"
else
textUpdate.innerText = "Something must of went wrong!"
}

最佳答案

你需要从你的函数中返回。向您的函数添加返回语句。

我发现您在调用函数后忘记了分号 ;

此外,您可以通过按 F12 并打开控制台选项卡来检查您的页面以查看错误是什么。

关于javascript - 为什么我的文本更新函数不显示文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58612129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com