I want to count the number of questions and display in index. On the other hand, the database have 2 types of questions, one need to count the index, one don't need to count.
If q_or_h ==1, i need to count++, if q_or_h == 2, no need to count.
Please help me how to write such code inside vue!
<div v-if="index<=questionIndex">
<div class="card-header" v-if="(question.q_or_h==2)" >
<div>{{question.question}}</div>
</div>
<div v-else >
<span :title="addCount(q_number)">{{q_number}} {{question.question}}</span>
<ol>
<li v-for="choice in question.answers">
<label for="">
<input type="radio"
:value="choice.is_correct==true?true:choice.answer"
:name="index"
v-model="correctAns[index]"
@click="choices(question.id,choice.id)"
>
{{choice.answer}}
</label>
</li>
</ol>
</div>
</div>
</div>
<div v-if="questionIndex!=questions.length">
<button class="btn btn-sm btn-success" @click="next(); postQuizChoice(); ">Next</button>
</div>
<div v-show="questionIndex==questions.length">
You Got: {{score()}}/{{questions.length}}
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
export default {
props:['times','taskId', 'taskQuestions', 'hasTaskPlayed'],
data(){
return{
questions:this.taskQuestions,
questionIndex:0,
correctAns:Array(this.taskQuestions.length).fill(false),
currentQuestion:0,
currentAnswer:0,
q_number:0,
}
},
mounted() {
},
computed:{
},
methods:{
next(){
},
choices(question, answer){
},
score(){
},
postQuizChoice(){
},
addCount(q_number){
this.q_number++;
}
}
}
</script>
I wrote the above code, howerver, not working, although without error. However, q_number shows the increment like this: 000, 101, 202, 303, 403, 404...