Reputation: 111
const quiz = new quiz(questions);
populate();
function Question(text, choices, answer){
this.text = text;
this.choices = choices;
this.answer = answer;
}
Question.prototype.correctAnswer = function(choices){
return choice === this.answer;
}
function Quiz(questions){
this.score = 0;
this.questions = questions;
this.questionIndex = 0;
}
quiz.prototype.getQuestionIndex = function(){
return this.questions[this.questionIndex];
}
quiz.prototype.isEnded = function(){
return this.questions.length === this.questionIndex;
}
quiz.protype.guess = function(answer){
this.questionIndex++;
if(this.getQuestionIndex().correctAnswer(answer)){
this.score++;
}
}
When I run this code, it says it cannot set 'getQuestionIndex' to undefined. But didn't Ique set it to 0? I set this.questionIndex to 0 in my Quiz constructor. What am I missing here?
Upvotes: 0
Views: 29
Reputation: 669
const quiz = new quiz(questions); should be const quiz = new Quiz(questions);
Upvotes: 1