Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Alexander Rizov4,910 Points
Answers are not counted properly. Help!
Ok, I realise I'll be kicking myself later for not figuring it out, but right now I'm at the end of my rope.
When the code runs it always counts 0 right answers and 1 wrong, even when I type nothing in the prompt window. The questions all appear in order and I'm not getting any error messages in the console.
Here's a link to my workspace snapshot: https://w.trhou.se/lce3j4v85i
Thanks in advance!
Steven Parker210,438 Points
The variables "correct" and "wrong" are created and set to 0 inside the loop, so they will only contain the result of the last question asked. Move the declarations out of the loop to make them global.
Also note that the "result" is being compared to the "question" instead of the "answer".