Skip to content

Commit

Permalink
Update code.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticalMike60t committed May 13, 2024
1 parent 957ae68 commit 5b81742
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions code.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,69 @@

(function () {
"use strict";


document.addEventListener("DOMContentLoaded", function() {
const quillButton = document.querySelector(".regen-button");
if (quillButton) {
quillButton.addEventListener("click", start);
} else {
console.error("Quill button not found.");
}
});

function getUrlParams(url) {
const params = new URLSearchParams(url);
const studentId = params.get("student");
return { studentId };
}

function displayQuestionsAndAnswers(questionSet) {
const contentDiv = document.querySelector(".student-container");
questionSet.forEach(questionData => {
const question = questionData.prompt;
const attempts = questionData.attempts;
const answers = attempts.map(attempt => attempt.response.text);
const question = questionSet.question;
const attempts = questionSet.attempts;
const questionDiv = document.createElement("div");
questionDiv.textContent = `Question: ${question}`;
contentDiv.appendChild(questionDiv);
answers.forEach(answer => {
const answerDiv = document.createElement("div");
answerDiv.textContent = `Answer: ${answer}`;
contentDiv.appendChild(answerDiv);
});
const regenButton = document.createElement("button");
regenButton.className = "regen-button";
contentDiv.appendChild(regenButton);
const separator = document.createElement("hr");
contentDiv.appendChild(separator);
});
}

const currentUrl = window.location.href;
const { studentId } = getUrlParams(currentUrl);
const jsonUrl = `https://www.quill.org/api/v1/active_activity_sessions/${studentId}.json`;

fetch(jsonUrl)
.then((response) => response.json())
.then((jsonData) => {
const questionId = jsonData.currentQuestion.question;
const apiUrl = `https://cms.quill.org/questions/${questionId}/responses`;

fetch(apiUrl)
.then((response) => response.json())
.then((data) => {
console.log("Response:", data);
data.forEach(answer => {
console.log("Answer: ", answer.text);

function start() {
const currentUrl = window.location.href;
const { studentId } = getUrlParams(currentUrl);
const jsonUrl = `https://www.quill.org/api/v1/active_activity_sessions/${studentId}.json`;

fetch(jsonUrl)
.then((response) => response.json())
.then((jsonData) => {
const questionId = jsonData.currentQuestion.question;
const apiUrl = `https://cms.quill.org/questions/${questionId}/responses`;

fetch(apiUrl)
.then((response) => response.json())
.then((data) => {
console.log("Response:", data);
data.forEach(answer => {
const contentDiv = document.querySelector(".student-container");
const answerDiv = document.createElement("div");
answerDiv.textContent = `Answer: ${answer.text}`;
contentDiv.appendChild(answerDiv);
});
})
.catch((error) => {
console.error("Error fetching data:", error);
});
})
.catch((error) => {
console.error("Error fetching data:", error);
});

const questionSet = jsonData.questionSet;
displayQuestionsAndAnswers(questionSet);
})
.catch((error) => {
console.error("Error fetching JSON data:", error);
});

const questionSet = jsonData.currentQuestion;
displayQuestionsAndAnswers(questionSet);
})
.catch((error) => {
console.error("Error fetching JSON data:", error);
});
}

start();
})();

0 comments on commit 5b81742

Please sign in to comment.