diff --git a/code/Justin/JavaScript/lab_quiz/index.html b/code/Justin/JavaScript/lab_quiz/index.html new file mode 100644 index 00000000..6e8f48a0 --- /dev/null +++ b/code/Justin/JavaScript/lab_quiz/index.html @@ -0,0 +1,50 @@ + + + + + + + + + Trivia + + + + +
+ + + + + + + +

+

Score: {{ score }}

+ + +

{{questions}}

+ + + +
+ + + + + + \ No newline at end of file diff --git a/code/Justin/JavaScript/lab_quiz/scripts.js b/code/Justin/JavaScript/lab_quiz/scripts.js new file mode 100644 index 00000000..bc6edd96 --- /dev/null +++ b/code/Justin/JavaScript/lab_quiz/scripts.js @@ -0,0 +1,52 @@ +const app = Vue.createApp({ + data(){ + return{ + difficulty: '', + selected: '', + questionType: '', + score: 0, + questions: [], + answers: [], + counter: 0, + correctAnswer: '' + } + }, + methods:{ + getData() { + axios({ + method: "get", + url: "https://opentdb.com/api.php?amount=10", + params: { + difficulty: this.selected, + type: this.questionType + }, + }).then((response) => { + console.log(response.data.results) + if (this.questionType === 'multiple'){ + questionObject = response.data['results'][this.counter] + console.log(questionObject) + this.questions = questionObject.question + this.correctAnswer = questionObject.correct_answer + this.answers[0] = questionObject.incorrect_answers[0] + this.answers[1] = questionObject.incorrect_answers[1] + this.answers[2] = questionObject.incorrect_answers[2] + this.answers[3] = questionObject.correct_answer + this.answers.sort(() => Math.random() - 0.5) + console.log(this.answers) + } else { + questionObject = response.data['results'][this.counter] + console.log(questionObject) + this.questions = questionObject.question + this.correctAnswer = questionObject.correct_answer + this.answers[0] = questionObject.correct_answer + this.answers[1] = questionObject.incorrect_answers[0] + } + }) + + } + + }, + mounted(){ + } +}) + diff --git a/code/Justin/JavaScript/lab_quiz/styles.css b/code/Justin/JavaScript/lab_quiz/styles.css new file mode 100644 index 00000000..e69de29b