Added a quiz for cia-triad lessons

This commit is contained in:
Max Geldner
2018-11-11 14:17:53 +01:00
committed by Nanne Baars
parent baff6b06f3
commit 50c88738c2
5 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,27 @@
$(function () {
var json = "";
var client = new XMLHttpRequest();
client.open('GET', '/WebGoat/lesson_js/questions.json');
client.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
json += client.responseText;
console.log("entry");
let questionsJson = json;
var questionsObj = JSON.parse(questionsJson);
let html = "";
jQuery.each(questionsObj, function(i, obj) {
jQuery.each(obj, function(j, quest) {
html += "<div id='question_" + j + "' class='quiz_question attack-container' name='question'><p>" + (j+1) + ".&nbsp;" + quest.text + "</p>";
html += "<fieldset>";
jQuery.each(quest.solutions, function(k, solution) {
solution = "Solution " + k + ": " + solution;
html += '<input type="checkbox" name="question_' + j +'_solution" value="' + solution + '">' + solution + '<br>';
});
html += "</fieldset></div>";
});
});
document.getElementById("q_container").innerHTML = html;
}
}
client.send();
});