I know I'm way off, but I can't find any reading that's helped me solve this. I'm trying to use a constructor function to create an array filled with Questions, Choices, and Answers for a quiz. I'm not sure of the syntax to push my object onto the array.
My constructor function is as follows:
// Create array to traverse(using jQuery) so that on clicking submit, the current question
//is deleted, and the next question in the array is loaded.
var questionsArray = [];
//Contructor Function to create questions and push them to the array
function Question (question, choices, answer){
this.question = question;
this.choices = choices;
this.answer = answer;
return questionsArray.push(); //This is way off I know, but I'm lost...
}
push(…)takes an argument. What do you want to push, the newQuestioninstance? You'd need to passthis, but actually it would be better to callquestionsArray.push(new Question(…))from outside the constructor. Btw, you should notreturnanything from a constructor function.