Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Practice Project Project Overview

Score will not increment

Everything else is working but my score will not increment.

https://w.trhou.se/wehmrqoxau Does any one have any suggestions?

hi, wen i click on the link, it tells the snapshot does'nt exist.

can you give the correct link .

The community has had some issues with links lately. The & # 13 entity gets added sometimes. Mostly on adding a hard line break i've noticed.

Here's the link again:

https://w.trhou.se/wehmrqoxau

3 Answers

Hi,

The logic is great in your code.

Made few modifications to your code and it works fine now. Corrected one:

https://w.trhou.se/9q17t5pvsa

Below were the changes done.

  • the function was called as question.answer. we can access the values of this function by calling 'q1.answer & q2.answer' Moved the function as quiz.answer to access the values of rightanswer and wronganswer.

  • Initially the answer value was not passed to be validated as correct/wrong answer. So modified the function button.onclick() to pass the answer which was selected by the user to be validated.

  • quiz.answer loop checks the answer and increments the score value. (Commente the quiz.checkAnswer and moved the logic to quiz.answer)

  • Included console.log to know the flow of changes.

Please let me know if you have any doubts.

Thanks, Aishu

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Aaron;

It appears as though the issue resides in your checkAnswer function:

Quiz.prototype.checkAnswer=function(){
  if(this.questions.answer===true){
    this.score++;
    this.questionIndex++;
  }else{
   this.questionIndex++; 
  }

}

In my solution I had to pass in a parameter into the function to be able to compare the answer with the current question.. Something along the lines of:

Quiz.prototype.checkAnswer = function(answer) {
    // do some comparison
};

As an aside, you can reduce you code a bit as follows:

Quiz.prototype.checkAnswer=function(){
  if(this.questions.answer===true){
    this.score++;
  }
   this.questionIndex++;  
};

Post back if you are still stuck.

Happy coding,
Ken

Thank you every one, its taken me 4 days to get this figured out I've rewritten the code at least 5 times