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 JavaScript Loops, Arrays and Objects Tracking Data Using Objects Mixing and Matching Arrays and Objects

Please help !, i dont know why the correct answers are not counting

var quiz = [ {question : "what is your name?", answer : "uche" },

{question : "how old are you ?", answer : "twenty"}, {question : "what is your profession", answer:"developer"}

]; var correctanswers = 0; var wronganswers= 0; var html; var response; var questionss; var answerss;

for (var i=0; i < quiz.length; i+=1) { questionss = quiz[i].question; answerss= quiz[i].answer; response= prompt(questionss); response= response.toLowerCase();

if (answerss===response) {

 correctanswers=+1;

} else { if (answerss!==response) {

 wronganswers+=1;

}

} }

html= "You have got " + correctanswers + " correct" ;
document.write(html);

1 Answer

Steven Parker
Steven Parker
231,236 Points

On this line, the count is not increased, but set to (positive) 1::

    correctanswers = +1;

What you probably intended here was to use the addition assignment operator instead ("correctanswers += 1")