({v, sort: Math.random()})) .sort((a, b) => a.sort - b.sort) .map(({v}) => v) } if (quiz.randomizeanswers) { quiz.questions.forEach(q => { q.answers = q.answers .map(v => ({v, sort: Math.random()})) .sort((a, b) => a.sort - b.sort) .map(({v}) => v) }) } const showAnswer = ref(false) const score = ref([]) const finalscore = ref() const isQuiz = ref() const questionNumber = ref(0) const validate = (a) => { showAnswer.value = a if (score.value.length == questionNumber.value) score.value.push(a.value) else score.value[score.value.length - 1] = a.value if (quiz.skipvalidation) nextQuestion() } const nextQuestion = () => { showAnswer.value = false questionNumber.value += 1 if (finished.value) { isQuiz.value = score.value.every(s => typeof s == "boolean") if (isQuiz.value) { var percent = (score.value.filter(s => s).length / quiz.questions.length * 100).toFixed() var r = Math.max(...Object.keys(quiz.results).filter(v => percent >= parseInt(v))) finalscore.value = { percent: percent, right: score.value.filter(s => s).length, wrong: score.value.filter(s => !s).length, _result: r } } else { finalscore.value = {} score.value.forEach(s => { if (s in finalscore.value) finalscore.value[s] += 1 else finalscore.value[s] = 1 }) Object.keys(finalscore.value).forEach(k => { finalscore.value[k] = (finalscore.value[k] / quiz.questions.length * 100).toFixed()}) max = Math.max(...Object.values(finalscore.value)) Object.keys(finalscore.value).forEach(k => { if (finalscore.value[k] == max) finalscore.value["_max"] = k }) } } } const progressStyle = computed(() => { progress = (questionNumber.value + (showAnswer.value ? 1 : 0)) / quiz.questions.length * 100 return `width: ${progress}%` }) const finished = computed(() => questionNumber.value >= (quiz.questions.length) ) const md = (t) => marked.parse(t || "") return { message: ’Hello Vue!’, questionNumber, showAnswer, quiz, validate, nextQuestion, progressStyle, finished, md, score, finalscore, isQuiz } } }).mount(’#quiz’) "> ({v, sort: Math.random()})) .sort((a, b) => a.sort - b.sort) .map(({v}) => v) } if (quiz.randomizeanswers) { quiz.questions.forEach(q => { q.answers = q.answers .map(v => ({v, sort: Math.random()})) .sort((a, b) => a.sort - b.sort) .map(({v}) => v) }) } const showAnswer = ref(false) const score = ref([]) const finalscore = ref() const isQuiz = ref() const questionNumber = ref(0) const validate = (a) => { showAnswer.value = a if (score.value.length == questionNumber.value) score.value.push(a.value) else score.value[score.value.length - 1] = a.value if (quiz.skipvalidation) nextQuestion() } const nextQuestion = () => { showAnswer.value = false questionNumber.value += 1 if (finished.value) { isQuiz.value = score.value.every(s => typeof s == "boolean") if (isQuiz.value) { var percent = (score.value.filter(s => s).length / quiz.questions.length * 100).toFixed() var r = Math.max(...Object.keys(quiz.results).filter(v => percent >= parseInt(v))) finalscore.value = { percent: percent, right: score.value.filter(s => s).length, wrong: score.value.filter(s => !s).length, _result: r } } else { finalscore.value = {} score.value.forEach(s => { if (s in finalscore.value) finalscore.value[s] += 1 else finalscore.value[s] = 1 }) Object.keys(finalscore.value).forEach(k => { finalscore.value[k] = (finalscore.value[k] / quiz.questions.length * 100).toFixed()}) max = Math.max(...Object.values(finalscore.value)) Object.keys(finalscore.value).forEach(k => { if (finalscore.value[k] == max) finalscore.value["_max"] = k }) } } } const progressStyle = computed(() => { progress = (questionNumber.value + (showAnswer.value ? 1 : 0)) / quiz.questions.length * 100 return `width: ${progress}%` }) const finished = computed(() => questionNumber.value >= (quiz.questions.length) ) const md = (t) => marked.parse(t || "") return { message: ’Hello Vue!’, questionNumber, showAnswer, quiz, validate, nextQuestion, progressStyle, finished, md, score, finalscore, isQuiz } } }).mount(’#quiz’) ">