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 triallaylazhang
5,111 PointsAmazing Quiz - What is the purpose of currentQuestionIndex?
Hi Treehouse Community,
I'm going through the Amazing Quiz challenge, but having trouble understanding the Quiz constructor. What is the purpose of the 'currentQuestionIndex' property below? Is this basically a counter that increase along with each guess?
function Quiz(questions) {
this.score = 0;
this.questions = questions;
this.currentQuestionIndex = 0;
}
1 Answer
Steven Parker
231,269 PointsYou're right that it gets used like a counter. But what it represents is the index number of the question that is currently being asked (or is about to be asked). It starts out with 0 since that is the index number of the first item of an array.
laylazhang
5,111 Pointslaylazhang
5,111 PointsThank you for confirming Steve! This makes a lot of sense after I spent another 2 hours trying to rebuild every block of code in this challenge.
I have a follow-up question unrelated to the challenge: I guess it's just kinda hard for a noob like me to even think about setting a counter to keep track of the quiz process. After all, I just learned the syntax of object constructor a few hours ago. To me OOP is a whole new way of thinking and tbh, right now it feels a little overwhelming. Would you say it gets better with more experience? should I slow down and look for other materials to help me understand OOP better before continuing the track?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsEverything gets better with experience. But sometimes pressing ahead will help you get to a point where things start to make more sense.