У меня очень простое приложение, работает как викторина.Я сделал сервис для централизации информации в моем случае вопросов и их ответов в массиве объектов.
проблема в том, что когда я нажимаю на любую из кнопок True / False, я вижу другой результат bool НЕ сравнивая то, что происходитназначенный в массиве объектов:
вот мой код service.ts:
export class QuizzlerService {
pickedAnswer: Boolean = false;
tracker = 0;
questions = [
{
q: 'Question 1',
a: true
},
{
q: 'Question 2',
a: true
},
{
q: 'Question 3',
a: false
},
{
q: 'Question 4',
a: false
},
{
q: 'Question 5',
a: true
},
{
q: 'Question 6',
a: true
}
];
onTrue () {
this.trueAnswer();
this.tracker++;
if (this.tracker >= this.questions.length) {
alert('finished!');
this.tracker = 0;
}
// if (this.tracker < this.questions.length - 1) {
// this.tracker++;
// } else {
// this.tracker = 0;
// alert('finished!');
// }
}
onFalse() {
this.falseAnswer();
this.tracker++;
if (this.tracker >= this.questions.length) {
alert('finished!');
this.tracker = 0;
}
}
trueAnswer() {
if (this.questions[this.tracker].a !== this.pickedAnswer) {
this.pickedAnswer = true;
// alert(this.questions[this.tracker].a);
alert('CORRECT!');
} else {
this.pickedAnswer = false;
// alert(this.questions[this.tracker].a);
alert('INCORRECT!');
}
}
falseAnswer() {
if (this.questions[this.tracker].a === this.pickedAnswer) {
this.pickedAnswer = false;
// alert(this.questions[this.tracker].a);
alert('CORRECT!');
} else {
this.pickedAnswer = true;
// alert(this.questions[this.tracker].a);
alert('INCORRECT!');
}
}
}
Вот скриншот из отладчика.
Не могу себе представить, что это заняло у менядень и так!
Большое спасибо за вашу помощь и руководство!
![debugger results](https://i.stack.imgur.com/78aLB.png)