Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MCQ{
- constructor(question,choice,answer,category){
- this.question = question
- this.choice = choice
- this.answer = answer
- this.category = category
- }
- getQuestion(){
- console.log(this.question+"\n(1)"+this.choice[0]+"\n(2)"+this.choice[1]+"\n(3)"+this.choice[2]+"\n(4)"+this.choice[3]);
- }
- }
- class Quiz{
- constructor() {
- this.questionPool = []; //declare the questionPool property of the Quiz class
- //populate 10 MCQs and push them into the array
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //1st question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //2nd question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //3rd question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //4th question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //5th question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //6thquestion
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //7th question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //8th question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //9th question
- this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
- "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //10th question
- }
- getNumberOfQuestions(){
- return this.questionPool.length
- }
- getQuestionAt(index){
- return this.questionPool[index]
- }
- }
- var quiz = new Quiz();
- for(var i = 0 ; i < quiz.getNumberOfQuestions() ; i++) {
- var q = quiz.getQuestionAt(i);
- console.log((i + 1) + ". " + q.getQuestion());
- console.log("Correct Answer: " + q.answer);
- console.log("Category: " + (q.category == 1 ? "IT" : "Football"));
- console.log();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement