JavaScript: Novice To Ninja Chapter 11 Project problem

First, thanks to those that helped with my previous problem with the project.

So I’ve worked my way up into Chapter 11 and made the project changes randomizing the questions selecting an answer from a list. And I get errors. So I got the source from https://github.com/spbooks/jsninja1/ and tried it. Same errors!

First error is ‘Uncaught TypeError: Cannot set property ‘asked’ of undefined’ on

function ask(question) {
console.log(“ask() invoked”);
// set the question.asked property to true so it’s not asked again
question.asked = true; <–ERROR ON THIS LINE
update($question,quiz.question + question.question + “?”);

Second error is ‘Uncaught TypeError: Cannot read property ‘answer’ of undefined’ on

 function check(answer) {
   console.log("check() invoked");
   if(answer === question.answer){   <--ERROR ON THIS LINE
     update($feedback,"Correct!","correct");

Have to admit I’ve got to read this chapter again. Callbacks, closres and currying…oh my! Perhaps too may topics in this one.

Thanks for helping a novice!

Dan

You’re not the only one facing the problem. It seems that the author was working on the assumption that the game ends when the countdown timer runs out - and not when all of the questions have been answered.

If there are no questions left to ask, it seems reasonable that that should also be a trigger for the game being over. You can update that part in the chooseQuestion() function as follows:

if (questions.length > 0) {
    question = questions[random(questions.length) - 1];
    ask(question);
} else {
    gameOver();
}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.