From 00e86714b40e3bb11b3a41bdd1ada85877ca33a7 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Mon, 4 Dec 2023 13:47:23 +0200 Subject: [PATCH] questions generated --- index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/index.js b/index.js index 826369e..23736a1 100644 --- a/index.js +++ b/index.js @@ -32,12 +32,15 @@ function finishQuiz() { } function initScore() { finishQuiz(); + const user = JSON.parse(localStorage.getItem("studData")); var sInfoName = document.getElementById("sInfoName"); var sInfoId = document.getElementById("sInfoId"); var sInfoTime = document.getElementById("sInfoTime"); sInfoName.innerText = "Student name: " + user.name; sInfoId.innerText = "Student ID: " + user.id; + + var sInfoTime = document.getElementById("sInfoTime"); var time_elapsed = new Date(); var start_time = new Date(user.startTime); console.log(start_time); @@ -59,3 +62,39 @@ function prevQ() { function questionSubmit() { } + +const sampleQuestion = { + title: "5x5?", + answers: [], +}; +const sampleAnswer = { + text: "answer 1", + correct: false, +}; + +//Questions +function generateQuestion(n1, n2, a1, a2, a3, a4) { + var question = JSON.parse(JSON.stringify(sampleQuestion)); + question.answers = [ + JSON.parse(JSON.stringify(sampleAnswer)), + JSON.parse(JSON.stringify(sampleAnswer)), + JSON.parse(JSON.stringify(sampleAnswer)), + JSON.parse(JSON.stringify(sampleAnswer)) + ]; + var answer_values = [a1, a2, a3, a4]; + question.title = n1 + "x" + n2; + for (let i = 0; i < 4; i++) { + question.answers[i].text = answer_values[i]; + if (n1 * n2 == answer_values[i]) + question.answers[i].correct = true + } + return question; +} +const questions = [ + generateQuestion(2, 1, 2, 1, 3, 21), + generateQuestion(2, 6, 7, 6, 4, 23), + generateQuestion(2, 5, 4, 5, 10, 24), + generateQuestion(3, 7, 2, 7, 14, 21), + generateQuestion(6, 6, 36, 6, 14, 21), +] +console.log(questions);