|
|
|
@ -2,19 +2,22 @@
|
|
|
|
|
<div class="card">
|
|
|
|
|
<div v-for="q in questions" :key="q.id">
|
|
|
|
|
<div v-if="route == q.id">
|
|
|
|
|
<h2>
|
|
|
|
|
{{ q.quiz[currentQuestion].questionText }}
|
|
|
|
|
</h2>
|
|
|
|
|
<h3 class="message">{{ message }}</h3>
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
:key="index"
|
|
|
|
|
v-for="(option, index) in q.quiz[currentQuestion].answerOptions"
|
|
|
|
|
@click="handleAnswerClick(option.isCorrect)"
|
|
|
|
|
class="btn ans-btn"
|
|
|
|
|
>
|
|
|
|
|
{{ option.answerText }}
|
|
|
|
|
</button>
|
|
|
|
|
<h3 v-if="complete" class="message">{{ $t("message.complete") }}</h3>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<h3 v-if="error" class="error">{{ $t("message.error") }}</h3>
|
|
|
|
|
<h2>
|
|
|
|
|
{{ q.quiz[currentQuestion].questionText }}
|
|
|
|
|
</h2>
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
:key="index"
|
|
|
|
|
v-for="(option, index) in q.quiz[currentQuestion].answerOptions"
|
|
|
|
|
@click="handleAnswerClick(option.isCorrect)"
|
|
|
|
|
class="btn ans-btn"
|
|
|
|
|
>
|
|
|
|
|
{{ option.answerText }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@ -22,39 +25,38 @@
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import questions from "@/assets/data/en/quiz.json";
|
|
|
|
|
import questions from "@/assets/translations/en/quiz.json";
|
|
|
|
|
import messages from "@/assets/translations/messages";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
currentQuestion: 0,
|
|
|
|
|
message: "",
|
|
|
|
|
startQuiz: false,
|
|
|
|
|
restart: false,
|
|
|
|
|
complete: false,
|
|
|
|
|
error: false,
|
|
|
|
|
questions: questions,
|
|
|
|
|
route: "",
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
i18n: { messages },
|
|
|
|
|
methods: {
|
|
|
|
|
handleAnswerClick(isCorrect) {
|
|
|
|
|
this.error = false;
|
|
|
|
|
let nextQuestion = this.currentQuestion + 1;
|
|
|
|
|
console.log(nextQuestion);
|
|
|
|
|
if (isCorrect == "true") {
|
|
|
|
|
this.message = "";
|
|
|
|
|
//always 3 questions per quiz
|
|
|
|
|
if (nextQuestion < 3) {
|
|
|
|
|
this.currentQuestion = nextQuestion;
|
|
|
|
|
} else {
|
|
|
|
|
this.message = "Well done, you've completed the quiz";
|
|
|
|
|
this.complete = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.message = "sorry, try again";
|
|
|
|
|
this.error = true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
console.log(this.$route.params.id);
|
|
|
|
|
this.route = this.$route.params.id;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|