이 질문은 전에 물어볼 수도 있지만이 멋진 커뮤니티가 나를 용서할 수 있다고 생각합니다. 나는 앱을 개발 중입니다. 의 버그가 나를 죽이고 :( 을 나는이 응용 프로그램마다를 실행하고 같은 원하는 행위 잠금 버튼을 누르면하지만 클릭 임의의 숫자 (4 일 수도 있고, 2) 후 정지하고 나에게이 오류 줄 때 :잡히지 않은 타입 오류 : 정의되지 않은 속성 'quest'을 읽을 수 없음
Uncaught TypeError: Cannot read property 'quest' of undefined
at QuestionReset
을
다음은 코드 번호입니다.
$(document).ready(function() {
var overwallScore = 0;
//prototype
function Question(quest, option1, option2, option3, correct) {
this.quest = quest;
this.option1 = option1;
this.option2 = option2;
this.option3 = option3;
this.correct = correct;
}
//creating questions
var question1 = new Question("1 + 1", 2, 3, 3, 1);
var question2 = new Question("2 + 2", 4, 3, 3, 2);
var question3 = new Question("3 + 3", 6, 3, 3, 3);
var question4 = new Question("4 + 4", 8, 3, 3, 1);
var question5 = new Question("5 + 5", 10, 3, 3, 2);
var question6 = new Question("6 + 6", 12, 3, 3, 3);
//the questions array
var questions = [];
//pushing questions to array
questions.push(question1);
questions.push(question2);
questions.push(question3);
questions.push(question4);
questions.push(question5);
questions.push(question6);
var randomQuestionIndex = Math.floor(Math.random() * 6 + 1);
function QuestionPre() {
randomQuestionIndex = Math.floor(Math.random() * 6 + 1);
document.querySelector("#question").innerHTML = questions[randomQuestionIndex].quest;
document.querySelector(".option-1").innerHTML = questions[randomQuestionIndex].option1;
document.querySelector(".option-2").innerHTML = questions[randomQuestionIndex].option2;
document.querySelector(".option-3").innerHTML = questions[randomQuestionIndex].option3;
}
QuestionPre();
function QuestionReset() {
randomQuestionIndex = Math.floor(Math.random() * 6 + 1);
document.querySelector("#question").innerHTML = questions[randomQuestionIndex].quest;
document.querySelector(".option-1").innerHTML = questions[randomQuestionIndex].option1;
document.querySelector(".option-2").innerHTML = questions[randomQuestionIndex].option2;
document.querySelector(".option-3").innerHTML = questions[randomQuestionIndex].option3;
}
document.querySelector(".lock-btn").addEventListener("click", function() {
if (document.querySelector(".option-" + questions[randomQuestionIndex].correct + "-check").checked === true) {
alert("Correct, such a Genius !");
overwallScore = overwallScore + 1;
QuestionReset();
} else {
alert("Wrong mate, such a bad luck !");
randomQuestionIndex = Math.floor(Math.random() * 6 + 1);
QuestionReset();
}
}); });
미리 감사드립니다.
'var에 randomQuestionIndex = Math.floor (인 Math.random() * 6 + 1);' randomQuestionIndex''의 값이'+ 1' 부분을 제거 범위 넘어 갈 수 있으며 그것을 잘 작동합니다. –
이 사람은 일하는 사람이 아니고 나는 왜 그 사람에게 나를 보내 주신지 고맙다는 것을 알지 못한다. 내 하루를 훨씬 기쁘게한다. 나는 내 하나님이이 일을하고 계셨다. FRENCH CRUSH 감사합니다. 다시 PLZ로 답하십시오. 나는 그걸 마크 할 수 있습니다. –