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 trial

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
230,274 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
230,274 Points

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