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

SAMUEL LAWRENCE
Courses Plus Student 8,447 PointsConstructor functions and Object literals
So I've been learning about Object literals and constructor functions. Constructor functions let you create multiple instances of an object type or kind. When we created the playlist, Andrew said we could add multiple playlists by creating a new playlist object. And with the Awesome Quiz app we can also create multiple Quiz objects and have them load say one after the other. So I tried to do that and realized I have no idea how to actually do that.
By that I mean, how do you load, or call the different instances of the quiz?
so I have the question object
function Question(text, choices, answer) {
this.text = text;
this.choices = choices;
this.answer = answer;
}
Question.prototype.isCorrectAnswer = function(choice) {
return this.answer === choice;
}
and I have the quiz object
function Quiz(questions) {
this.score = 0;
this.questions = questions;
this.currentQuestionIndex = 0;
}
Quiz.prototype.guess = function(answer) {
if(this.getCurrentQuestion().isCorrectAnswer(answer)) {
this.score++;
}
this.currentQuestionIndex++;
};
Quiz.prototype.getCurrentQuestion = function() {
return this.questions[this.currentQuestionIndex];
};
Quiz.prototype.hasEnded = function() {
return this.currentQuestionIndex >= this.questions.length;
};
I have the questions array with multiple instances of the question object
//Create Questions
var questions = [
new Question("What is my name?", ["Samu", "Samuel"], "Samuel"),
new Question("Where am I from?", ["Dominica", "China"], "Dominica"),
new Question("How old am I?", [37, 36], 36),
new Question("Where do I live?", ["Beijing", "Roseau"], "Beijing"),
new Question("I am married", ["True", "False"], "True"),
new Question("I have been to Korea?", ["Yes", "No"], "No"),
new Question("I love poker?", ["Yes", "No"], "Yes")
];
in the app.js file I created a quiz by calling well have a look
//Create Questions
var questions = [
new Question("What is my name?", ["Samu", "Samuel"], "Samuel"),
new Question("Where am I from?", ["Dominica", "China"], "Dominica"),
new Question("How old am I?", [37, 36], 36),
new Question("Where do I live?", ["Beijing", "Roseau"], "Beijing"),
new Question("I am married", ["True", "False"], "True"),
new Question("I have been to Korea?", ["Yes", "No"], "No"),
new Question("I love poker?", ["Yes", "No"], "Yes")
];
var questions1 = [
new Question("What is my Height?", ["6' 2", "6' 1"], "6' 2"),
new Question("Where am I from?", ["Dominica", "China"], "Dominica"),
new Question("How old am I?", [37, 36], 36),
new Question("Where do I live?", ["Beijing", "Roseau"], "Beijing"),
new Question("I am married", ["True", "False"], "True"),
new Question("I have been to Korea?", ["Yes", "No"], "No"),
new Question("I love poker?", ["Yes", "No"], "Yes")
];
//Create Quiz
var quiz = new Quiz(questions);
var quiz1 = new Quiz(questions1);
//Display quiz
QuizUI.displayNext();
How to I also get the questions1
and quiz1
to display. We've never actually done it through out the course. How Can I get it to also display to the UI?
Do I have to go in the quiz-ui.js file and change every instance of the quiz to quiz1 and question(s) to question(s)1?
Wow I'm just realizing how lost I am. Here is a snapshot of my workspace. https://w.trhou.se/aoyr9ly9sn
Please help Steven Parker and Jennifer Nordell
1 Answer

Steven Parker
242,191 PointsYou could get questions1 to display by passing them when creating the "quiz" object:
//Create Quiz
var quiz = new Quiz(questions1);
The QuizUI module only works with the object named "quiz".