我的代码似乎是正确的,但我不知道为什么我收到此错误:遗漏的类型错误:无法读取空
Uncaught TypeError: Cannot read property 'toUpperCase' of null
这里是我的代码:
//The function is executed after someone clicks the "Take the Quiz"
function startquiz() {
//The variable for the first question
var FirstAnwser = prompt("Who posted the first youtube video?");
//The if statement for the first question
if (FirstAnwser.toUpperCase() === 'JAWED KARIM') {
//If the person is correct a dialog box that says correct pops up
alert("Correct");
//The Variable for the second question
var SecondAnwser = prompt("When was the domain name youtube.com activated?");
if (SecondAnwser.toUpperCase() === 'FEBUARY 14, 2005') {
alert("Correct");
var ThirdAnwser = prompt("What was the first video on youtube called?");
if (ThirdAnwser.toUpperCase() === 'ME AT THE ZOO') {
alert("Correct");
} else {
alert("Sorry, That is Wrong");
}
} else {
alert("Sorry, That is Wrong");
}
} else {
//If the person is wrong a dialog box pops up which says "Sorry, That is wrong"
alert("Sorry, That is Wrong");
}
}
错误发生在if (SecondAnwser.toUpperCase() === 'FEBUARY 14, 2005') {
第一个迂腐的东西:单词拼写为“answer” – Pointy
和'FEBUARY'拼错了 – epascarello
并且为了让它失效,我无法重现这个问题:https://jsfiddle.net/jt319dj0/。如果我想点击'取消'会有帮助。 –