Angular LMS app
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

172 lines
4.0 KiB

  1. import { Component, OnInit } from '@angular/core';
  2. import { Location } from '@angular/common';
  3. import { NgxSiemaOptions, NgxSiemaService } from 'ngx-siema';
  4. @Component({
  5. selector: 'app-quiz',
  6. templateUrl: './quiz.component.html',
  7. styleUrls: ['./quiz.component.scss']
  8. })
  9. export class QuizComponent implements OnInit {
  10. options: NgxSiemaOptions = {
  11. selector: '.siema',
  12. duration: 300,
  13. easing: 'ease-out',
  14. perPage: 1,
  15. startIndex: 0,
  16. draggable: false,
  17. threshold: 20,
  18. loop: false,
  19. onInit: () => {
  20. // runs immediately after first initialization
  21. },
  22. onChange: () => {
  23. // runs after slide change
  24. },
  25. };
  26. quizSegment: string = 'START_PAGE';
  27. showQuestionList: boolean = false;
  28. selectedQuestion: any;
  29. questionList = [{
  30. id: 1,
  31. question: 'Which sentence is corrent? "1. Ramu went to School \n 2. School went Ramu"',
  32. userAnswer: 0,
  33. correctAnswer: 1,
  34. options: [{
  35. id: 1,
  36. text: '1 is correct',
  37. }, {
  38. id: 2,
  39. text: '2 is correct',
  40. }, {
  41. id: 3,
  42. text: 'Both are correct',
  43. }, {
  44. id: 4,
  45. text: 'Both are wrong',
  46. }]
  47. }, {
  48. id: 2,
  49. question: 'How much is 16x16 ?',
  50. userAnswer: 0,
  51. correctAnswer: 4,
  52. options: [{
  53. id: 1,
  54. text: '30000',
  55. }, {
  56. id: 2,
  57. text: '540',
  58. }, {
  59. id: 3,
  60. text: '156',
  61. }, {
  62. id: 4,
  63. text: '256',
  64. }]
  65. }, {
  66. id: 3,
  67. question: 'Who is Jackie Chan ?',
  68. userAnswer: 0,
  69. correctAnswer: 2,
  70. options: [{
  71. id: 1,
  72. text: 'Dancer',
  73. }, {
  74. id: 2,
  75. text: 'Actor',
  76. }, {
  77. id: 3,
  78. text: 'Singer',
  79. }, {
  80. id: 4,
  81. text: 'Gambler',
  82. }]
  83. }, {
  84. id: 4,
  85. question: 'Who is Newton ?',
  86. userAnswer: 0,
  87. correctAnswer: 3,
  88. options: [{
  89. id: 1,
  90. text: 'Dancer',
  91. }, {
  92. id: 2,
  93. text: 'Actor',
  94. }, {
  95. id: 3,
  96. text: 'Scientist',
  97. }, {
  98. id: 4,
  99. text: 'Gambler',
  100. }]
  101. }];
  102. constructor(
  103. private location: Location,
  104. private ngxSiemaService: NgxSiemaService
  105. ) { }
  106. ngOnInit(): void {
  107. this.selectedQuestion = this.questionList[0];
  108. }
  109. next() {
  110. if (this.selectedQuestion.id === this.questionList[this.questionList.length - 1].id) {
  111. this.quizSegment = 'END_PAGE';
  112. } else {
  113. this.ngxSiemaService.next(1);
  114. this.ngxSiemaService.currentSlide().subscribe((index) => {
  115. this.selectedQuestion = this.questionList[index.currentSlide];
  116. }).unsubscribe();
  117. }
  118. }
  119. goToSlide(index: number) {
  120. this.ngxSiemaService.goTo(index);
  121. this.selectedQuestion = this.questionList[index];
  122. this.showQuestionList = false;
  123. }
  124. prev() {
  125. this.ngxSiemaService.prev(1);
  126. this.ngxSiemaService.currentSlide().subscribe((index) => {
  127. this.selectedQuestion = this.questionList[index.currentSlide];
  128. }).unsubscribe();
  129. }
  130. back() {
  131. this.location.back();
  132. }
  133. isAnswerWrong(correctAnswer: number, userAnswer: number) {
  134. if (correctAnswer !== userAnswer) {
  135. console.log("Called");
  136. window.navigator.vibrate(1000);
  137. }
  138. }
  139. getCorrectAnswersCount() {
  140. return this.questionList.filter((question) => {
  141. return question.correctAnswer === question.userAnswer;
  142. }).length;
  143. }
  144. getWrongAnswersCount() {
  145. return this.questionList.filter((question) => {
  146. return question.correctAnswer !== question.userAnswer && question.userAnswer !== 0;
  147. }).length;
  148. }
  149. getUnAttendedAnswersCount() {
  150. return this.questionList.filter((question) => {
  151. return question.userAnswer === 0;
  152. }).length;
  153. }
  154. }