diff --git a/src/components/Quiz.vue b/src/components/Quiz.vue index d4edb52..0dd89cf 100644 --- a/src/components/Quiz.vue +++ b/src/components/Quiz.vue @@ -3,10 +3,11 @@ import { callAPI, postAPI } from '@/helpers/callAPI.js' import router from '@/router/router.js' import Loading from '@/components/Loading.vue' import { useSessionStore } from '@/stores/sessionStore.js' -import { boolean } from 'yup' +import { array, boolean } from 'yup' import Results from '@/components/Results.vue' import { apiDirection } from '@/helpers/others.js' import Score from '@/components/Score.vue' +import { shuffle } from '@/helpers/Maths.js' export default { name: 'Quiz', @@ -23,11 +24,12 @@ export default { responses: [], quizID: null, // until we created on the db we don't know the id matchID: null, // same with match - seshStore: useSessionStore().user + seshStore: useSessionStore().user, + options: ['option_a', 'option_b', 'option_c'] } }, - // reactive conditions + // reactive conditions computed: { showScore(){ return !this.mode.isMultiplayer && this.questions.length && this.points>0 && @@ -274,14 +276,17 @@ export default { await this.getQuestionsFromAPIForNewQuiz() useSessionStore().user.isConnected && this.mode.gameMode !== "zen" && await this.createQuizAndMatchOnDB() + this.options = [...shuffle(this.options)] }, watch: { counter(value) { // when matches finish and game mode is not zen if (useSessionStore().user.isConnected && value>this.questions.length-1 && this.mode.gameMode !== "zen") this.handleFinishedQuiz() + // to shuffle options + this.options = [...shuffle(this.options)] }, - } + }, } @@ -314,22 +319,23 @@ export default { {{questions[counter].title}} + diff --git a/src/helpers/Maths.js b/src/helpers/Maths.js new file mode 100644 index 0000000..7958843 --- /dev/null +++ b/src/helpers/Maths.js @@ -0,0 +1,10 @@ + +export const shuffle = (array) => { + + for (let i = array.length - 1; i > 0; i--) { + let j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]] + } + return array + +}