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 trialShenerica Hines
7,690 PointsVariable named correct
Hi I'm confused on how the correct variable starts off at 0 and then for each question += 1.
2 Answers
Steven Parker
231,248 PointsOn line 5, "let correct = 0;" creates the variable and sets it to 0 to begin with.
Then, on lines 20, 24, 28 ...etc. the "correct += 1" raises the value by one each time, but the "if" statement only lets this happen if the answer was right.
Does that clear it up?
Mateusz Dobrzynski
1,631 PointsLet correct = 0, got it . Thanks for a quick reply !
Mateusz Dobrzynski
1,631 PointsMateusz Dobrzynski
1,631 PointsI had similar issue with line twenty as undefined. problem solved when I assigned value to 1 after first answer :
let score = 0;
// 2. Store the rank of a player let rank = '';
// 3. Select the <main> HTML element const main = document.querySelector('main')
/*
Steven Parker
231,248 PointsSteven Parker
231,248 PointsThe problem here is the variable was created with the name "score", but in the questions it is referred to as "correct".
The name "correct" was never propertly declared or initialized.