Skip to content

Instantly share code, notes, and snippets.

@AntiKippi
Created November 16, 2023 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntiKippi/01e9396bf8287dc5d957b76f6f0f8cf6 to your computer and use it in GitHub Desktop.
Save AntiKippi/01e9396bf8287dc5d957b76f6f0f8cf6 to your computer and use it in GitHub Desktop.
TU Wien DWI WS2023 Extract Miniquiz Answers
{
for (let content in H5PIntegration.contents) {
let jc = JSON.parse(H5PIntegration.contents[content]["jsonContent"]);
for (let chapter of jc["chapters"]) {
let output = chapter["metadata"]["title"] + "\n";
for (let question of chapter["params"]["content"][0]["content"]["params"]["questions"]) {
output += "Question: " + question["params"]["question"];
output += "Answer(s): \n";
if (question["params"]["answers"]) {
for (let answer of question["params"]["answers"]) {
if (answer["correct"]) {
output += answer["text"] + "\n";
}
}
}
else if (question["params"]["correct"]) {
output += question["params"]["correct"] + "\n";
}
else {
console.warn("Could not extract answer")
}
output += "\n";
}
console.log(output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment