Added a quiz for cia-triad lessons
This commit is contained in:
27
webgoat-lessons/cia/src/main/resources/js/quiz.js
Normal file
27
webgoat-lessons/cia/src/main/resources/js/quiz.js
Normal 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) + ". " + 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();
|
||||
});
|
Reference in New Issue
Block a user