我的代碼似乎是正確的,但我不知道爲什麼我收到此錯誤:遺漏的類型錯誤:無法讀取空
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/。如果我想點擊'取消'會有幫助。 –