javascript - 未捕获的类型错误:无法读取未定义的属性“选择”
问题描述
我正在尝试改进我的 JavaScript,我发现了这个:https ://jsbin.com/qacolagedo/edit?html,js,output 。
但在开发人员工具中,我收到此错误:
qacolagedo.js:54 Uncaught TypeError: Cannot read property 'choices' of undefined
at renderQuestions (qacolagedo.js:54)
at checkAnswer (qacolagedo.js:72)
at HTMLInputElement.onclick (runner:1)
这怎么能解决?
先感谢您。
解决方案
调用finished
函数后停止执行代码。为此,您可以编写return;
else {
alert("You have a total of " + sumPoints + "/4" + " correct answers!");
finished();
return;
}
并且发生错误是因为您尝试choices
从不存在的allQuestions
数组项中获取。不存在,因为zCount
超过allQuestions
数组的长度。
推荐阅读
- python - 当有其他参数时如何在Django中绑定表单
- php - Ionic Angular Query 字符串解析以登录
- google-sheets - google sheet api:获取集合中每个电子表格的单元格值
- azure - CosmosDB:高效地从大型容器迁移记录
- python - 在一天中的特定时间运行 Python 函数
- r - 如何在 X 轴上绘制 R 多个变量,在 Y 轴上绘制它们的值?
- lua - Lua 中的串联 AOB
- uwp - 为多实例 uwp 应用程序实现桌面扩展
- json - 如何从 Springboot 更新 mongoDb 中的单个 JSON 字段
- php - Laravel POST 请求返回 204 响应