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 trialIgnacio Uriz
5,042 PointsWhen I print the counter it says undefined and NaN
var counter; var wrong; var questions=[ ["Is spain better than Czech republic?Answer with yes or no","yes"], ["What is the biggest country in the world","Russia"], ["What is the smallest country","Baticano"] ];
var question1=prompt(questions[0][0]); var question2=prompt(questions[1][0]); var question3=prompt(questions[2][0]);
if(questions[0][0]===questions[0][1] ) { counter+=1; } else{ wrong+=1; } if(questions[1][0]===questions[0][1] ) { counter+=1; } else{ wrong+=1; } if(questions[2][0]===questions[0][1] ) { counter+=1; } else{ wrong+=1; } document.write("<h1>You got " +counter + "right,But you got " + wrong + "incorrect");
1 Answer
Ignacio Uriz
5,042 PointsThank you David
David Olson
8,690 PointsDavid Olson
8,690 Pointsyour var counter and wrong should be set to = 0. That should fix it. var counter = 0; var wrong = 0;
I think for some reason it was not able to add 1 since the original value was null ? hence the not a number error.
Also side note, you dont need to define your questions as variables since they are not reused.