[英]My simple if-statement works on Google and FireFox but not on safari? I am building a quiz app in React.js and the logic is pretty simple
所以代码非常简单,我将用户的答案与正确答案进行比较。 我正在使用 useState() 来管理正确的答案,并且我正在通过点击事件提取用户的答案。
// This is the correct answer according to the data
let correctAnswer = await questionArray[questionNumber-1].correctAnswer;
console.log("Correct Answer: "+ correctAnswer)
// This is the answer the user choise
let userAnswer = e.target.outerText
console.log("User Answer: " + userAnswer)
// This is comparing Correct Answer against the User's Answer
if (correctAnswer === userAnswer){
console.log('CORRECT')
}
else{
// Most of the time safari will run the else statement but every once in awhile it will correctly respect the if statement
console.log("WRONG")
}
如您所见,Google 将正确执行 if 语句,但 Safari 不会。
由于问题是 Safari 特有的问题,我认为这是某种浏览器问题,但代码很简单,我想知道它是否与 useState 的异步特性有关。
非常感谢任何回应(:
嗯..奇怪,但你检查过值的长度吗? 我觉得它必须与值的长度或 safari 日志中显示的额外 3 行代码(Quiz.jsx 行号)有关。也许那些被排除的行会引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.