diff options
Diffstat (limited to 'admin/public/script.js')
-rw-r--r-- | admin/public/script.js | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/admin/public/script.js b/admin/public/script.js index ff6fa2b..d9fd30e 100644 --- a/admin/public/script.js +++ b/admin/public/script.js @@ -1,22 +1,27 @@ -fetch("api/questions").then(questions => questions.json()).then(questions => { - fetch("api/answers").then(answers => answers.json()).then(answers => { - questions.forEach(question => question.answers = []); - answers.forEach(answer => questions[answer.question_id - 1].answers.push(answer)); - render(questions); - }); -}); +fetch("api/questions") + .then((questions) => questions.json()) + .then((questions) => { + fetch("api/answers") + .then((answers) => answers.json()) + .then((answers) => { + questions.forEach((question) => (question.answers = [])); + answers.forEach((answer) => questions[answer.question_id - 1].answers.push(answer)); + render(questions); + }); + }); -function render(questions) -{ - console.log(questions); - const teacher = document.querySelector("ul#teacher"); - const pupil = document.querySelector("ul#pupil"); - questions.forEach(question => { - const list = question.type === "teacher" ? teacher : pupil; - let answers = ""; - question.answers.forEach(answer => { - answers += `<li>${answer.name} ${answer.middlename ? answer.middlename + " " : ""}${answer.surname}: ${answer.count}</li>` - }); - list.insertAdjacentHTML("beforeend", `<li>${question.question}<br><ol>${answers}</ol></li>`); - }); +function render(questions) { + console.log(questions); + const teacher = document.querySelector("ul#teacher"); + const pupil = document.querySelector("ul#pupil"); + questions.forEach((question) => { + const list = question.type === "teacher" ? teacher : pupil; + let answers = ""; + question.answers.forEach((answer) => { + answers += `<li>${answer.name} ${answer.middlename ? answer.middlename + " " : ""}${answer.surname}: ${ + answer.count + }</li>`; + }); + list.insertAdjacentHTML("beforeend", `<li>${question.question}<br><ol>${answers}</ol></li>`); + }); } |