Skip to content
Snippets Groups Projects
Commit 9de42eca authored by MEKHININI ELIES's avatar MEKHININI ELIES :speech_balloon:
Browse files

:twisted_rightwards_arrows: merge Develop

Merge branch 'develop' into 'main'
parents 45acfd69 3012d40a
Branches main
1 merge request!23Develop
Pipeline #291942 failed with stages
in 20 seconds
...@@ -3,72 +3,54 @@ ...@@ -3,72 +3,54 @@
<p>Category : {{ decodeHtml(actualQuestion.category) }}</p> <p>Category : {{ decodeHtml(actualQuestion.category) }}</p>
<div class="title"> <div class="title">
<h4>Question {{ actualQuestionIndex + 1 }}/{{ questions.length }}</h4> <h4>Question {{ actualQuestionIndex + 1 }}/{{ questions.length }}</h4>
<br /> <h4>Score : {{ score }}</h4>
<h2>{{ decodeHtml(actualQuestion.question) }}</h2> <h2>{{ decodeHtml(actualQuestion.question) }}</h2>
</div> </div>
</div> </div>
<div> <div>
<div *ngIf="actualQuestion.type === 'boolean'" class="button-container"> <div *ngIf="actualQuestion.type === 'boolean'" class="button-container">
<button <button (click)="handleClick('True', 0)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[0],
[ngClass]="{ 'wrong-answer': actualQuestion?.correct_answer === 'False' && showResults[0],
'button-selection': !showResult, 'good-answer': actualQuestion?.correct_answer === 'True' && showResults[0]
'wrong-answer': actualQuestion?.correct_answer === 'False' && showResult, }">
'good-answer': actualQuestion?.correct_answer === 'True' && showResult
}"
>
TRUE TRUE
</button> </button>
<button <button (click)="handleClick('False', 1)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[1],
[ngClass]="{ 'wrong-answer': actualQuestion?.correct_answer === 'True' && showResults[1],
'button-selection': !showResult, 'good-answer': actualQuestion?.correct_answer === 'False' && showResults[1]
'wrong-answer': actualQuestion?.correct_answer === 'True' && showResult, }">
'good-answer': actualQuestion?.correct_answer === 'False' && showResult
}"
>
FALSE FALSE
</button> </button>
</div> </div>
<div *ngIf="actualQuestion.type === 'multiple'" class="button-container"> <div *ngIf="actualQuestion.type === 'multiple'" class="button-container">
<button <button (click)="handleClick(answers[0], 0)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[0],
[ngClass]="{ 'wrong-answer': actualQuestion.correct_answer !== answers[0] && showResults[0],
'button-selection': !showResult, 'good-answer': actualQuestion.correct_answer === answers[0] && showResults[0]
'wrong-answer': actualQuestion.correct_answer !== answers[0] && showResult, }">
'good-answer': actualQuestion.correct_answer === answers[0] && showResult
}"
>
{{ decodeHtml(answers[0]) }} {{ decodeHtml(answers[0]) }}
</button> </button>
<button <button (click)="handleClick(answers[1], 1)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[1],
[ngClass]="{ 'wrong-answer': actualQuestion.correct_answer !== answers[1] && showResults[1],
'button-selection': !showResult, 'good-answer': actualQuestion.correct_answer === answers[1] && showResults[1]
'wrong-answer': actualQuestion.correct_answer !== answers[1] && showResult, }">
'good-answer': actualQuestion.correct_answer === answers[1] && showResult
}"
>
{{ decodeHtml(answers[1]) }} {{ decodeHtml(answers[1]) }}
</button> </button>
<button <button (click)="handleClick(answers[2], 2)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[2],
[ngClass]="{ 'wrong-answer': actualQuestion.correct_answer !== answers[2] && showResults[2],
'button-selection': !showResult, 'good-answer': actualQuestion.correct_answer === answers[2] && showResults[2]
'wrong-answer': actualQuestion.correct_answer !== answers[2] && showResult, }">
'good-answer': actualQuestion.correct_answer === answers[2] && showResult
}"
>
{{ decodeHtml(answers[2]) }} {{ decodeHtml(answers[2]) }}
</button> </button>
<button <button (click)="handleClick(answers[3], 3)" [ngClass]="{
(click)="showResult = true" 'button-selection': !showResults[3],
[ngClass]="{ 'wrong-answer': actualQuestion.correct_answer !== answers[3] && showResults[3],
'button-selection': !showResult, 'good-answer': actualQuestion.correct_answer === answers[3] && showResults[3]
'wrong-answer': actualQuestion.correct_answer !== answers[3] && showResult, }">
'good-answer': actualQuestion.correct_answer === answers[3] && showResult
}"
>
{{ decodeHtml(answers[3]) }} {{ decodeHtml(answers[3]) }}
</button> </button>
</div> </div>
...@@ -78,4 +60,4 @@ ...@@ -78,4 +60,4 @@
@if (actualQuestionIndex === questions.length - 1) { Finish quiz } @else { Next question } @if (actualQuestionIndex === questions.length - 1) { Finish quiz } @else { Next question }
</button> </button>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -12,13 +12,15 @@ export class QuestionComponent implements OnInit { ...@@ -12,13 +12,15 @@ export class QuestionComponent implements OnInit {
private questionSerivce: QuestionService, private questionSerivce: QuestionService,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
private router: Router private router: Router
) {} ) { }
isLoading: boolean = false; isLoading: boolean = false;
questions: any = []; questions: any = [];
actualQuestion: any; actualQuestion: any;
actualQuestionIndex: number = -1; actualQuestionIndex: number = -1;
showResults: boolean[] = [false, false, false, false];
showResult: boolean = false; showResult: boolean = false;
answers: string[] = []; answers: string[] = [];
score: number = 0;
ngOnInit(): void { ngOnInit(): void {
this.isLoading = true; this.isLoading = true;
this.activatedRoute.queryParams.subscribe((params) => { this.activatedRoute.queryParams.subscribe((params) => {
...@@ -57,6 +59,7 @@ export class QuestionComponent implements OnInit { ...@@ -57,6 +59,7 @@ export class QuestionComponent implements OnInit {
} else { } else {
this.actualQuestionIndex++; this.actualQuestionIndex++;
this.actualQuestion = this.questions[this.actualQuestionIndex]; this.actualQuestion = this.questions[this.actualQuestionIndex];
this.showResults = [false, false, false, false];
this.showResult = false; this.showResult = false;
if (this.actualQuestion.type === 'multiple') { if (this.actualQuestion.type === 'multiple') {
this.answers = [...this.actualQuestion.incorrect_answers, this.actualQuestion.correct_answer]; this.answers = [...this.actualQuestion.incorrect_answers, this.actualQuestion.correct_answer];
...@@ -77,4 +80,20 @@ export class QuestionComponent implements OnInit { ...@@ -77,4 +80,20 @@ export class QuestionComponent implements OnInit {
[array[i], array[j]] = [array[j], array[i]]; [array[i], array[j]] = [array[j], array[i]];
} }
} }
handleClick(res: string, index: number) {
if (this.showResult) return;
console.log(res);
if (res === this.actualQuestion.correct_answer) {
this.score++;
} else {
this.answers.forEach((answer, index) => {
if (answer === this.actualQuestion.correct_answer) {
this.showResults[index] = true;
}
});
}
this.showResults[index] = true;
this.showResult = true;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment