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.

JavaScript Object-Oriented JavaScript (2015) Practice Project User Interface Code

laylazhang
laylazhang
5,111 Points

Amazing 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
Steven Parker
216,148 Points

You'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
laylazhang
5,111 Points

Thank 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
Steven Parker
216,148 Points

Everything gets better with experience. But sometimes pressing ahead will help you get to a point where things start to make more sense.