Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. class MCQ{
  2. constructor(question,choice,answer,category){
  3. this.question = question
  4. this.choice = choice
  5. this.answer = answer
  6. this.category = category
  7. }
  8. getQuestion(){
  9. console.log(this.question+"\n(1)"+this.choice[0]+"\n(2)"+this.choice[1]+"\n(3)"+this.choice[2]+"\n(4)"+this.choice[3]);
  10. }
  11. }
  12.  
  13. class Quiz{
  14. constructor() {
  15. this.questionPool = []; //declare the questionPool property of the Quiz class
  16.  
  17. //populate 10 MCQs and push them into the array
  18. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  19. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //1st question
  20. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  21. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //2nd question
  22. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  23. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //3rd question
  24. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  25. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //4th question
  26. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  27. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //5th question
  28. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  29. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //6thquestion
  30. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  31. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //7th question
  32. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  33. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //8th question
  34. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  35. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //9th question
  36. this.questionPool.push(new MCQ("What is RAM?", ["Random Access Memory",
  37. "A kind of Sheep", "Roughly force something into place", "None of the above"], 0, 1)); //10th question
  38. }
  39.  
  40. getNumberOfQuestions(){
  41. return this.questionPool.length
  42. }
  43.  
  44. getQuestionAt(index){
  45. return this.questionPool[index]
  46. }
  47.  
  48.  
  49. }
  50. var quiz = new Quiz();
  51. for(var i = 0 ; i < quiz.getNumberOfQuestions() ; i++) {
  52. var q = quiz.getQuestionAt(i);
  53. console.log((i + 1) + ". " + q.getQuestion());
  54. console.log("Correct Answer: " + q.answer);
  55. console.log("Category: " + (q.category == 1 ? "IT" : "Football"));
  56. console.log();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement