2021-03-18 20:08:19 -07:00
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
|
|
{% block body %}
|
2021-04-17 13:14:29 -07:00
|
|
|
<main class="container-fluid">
|
|
|
|
<h1 class="text-center">Quiz The Word</h1>
|
2021-08-29 18:56:29 -07:00
|
|
|
<div class="row justify-content-center">
|
|
|
|
<div class="col-md col-lg-7 align-content-center question">
|
|
|
|
<div class="card question-content">
|
|
|
|
<h5 id="question-text"></h5>
|
|
|
|
<div id="question-choices" class="list-group"></div>
|
2021-04-03 15:59:32 -07:00
|
|
|
</div>
|
2021-04-17 13:14:29 -07:00
|
|
|
</div>
|
2021-04-03 15:59:32 -07:00
|
|
|
</div>
|
2021-03-18 20:08:19 -07:00
|
|
|
|
2021-08-29 18:56:29 -07:00
|
|
|
<ul class="nav nav-pills justify-content-center mt-2">
|
2021-04-17 13:14:29 -07:00
|
|
|
<li class="nav-item" role="presentation">
|
2021-08-29 18:56:29 -07:00
|
|
|
<button class="nav-link active difficulty-selection" id="btn-show-easy" type="button" aria-controls="easy" aria-selected="true">Easy
|
2021-04-17 13:14:29 -07:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item" role="presentation">
|
2021-08-29 18:56:29 -07:00
|
|
|
<button class="nav-link difficulty-selection" id="btn-show-medium" type="button" aria-controls="medium" aria-selected="false">Medium
|
2021-04-17 13:14:29 -07:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li class="nav-item" role="presentation">
|
2021-08-29 18:56:29 -07:00
|
|
|
<button class="nav-link difficulty-selection" id="btn-show-hard" type="button" aria-controls="hard" aria-selected="false">Hard
|
2021-04-17 13:14:29 -07:00
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</main>
|
2021-03-18 20:08:19 -07:00
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block scripts %}
|
2021-04-17 13:14:29 -07:00
|
|
|
<script>
|
2021-08-29 18:56:29 -07:00
|
|
|
let questions = [
|
|
|
|
{{ easy.get_dict_shuffled_choices()|tojson }},
|
|
|
|
{{ medium.get_dict_shuffled_choices()|tojson }},
|
|
|
|
{{ hard.get_dict_shuffled_choices()|tojson }},
|
|
|
|
];
|
|
|
|
let difficulty_selection = $(".difficulty-selection");
|
|
|
|
let current_difficulty = 1;
|
|
|
|
|
|
|
|
change_difficulty(current_difficulty);
|
|
|
|
|
|
|
|
difficulty_selection.on("click", (event) => {
|
|
|
|
difficulty_selection.removeClass("active");
|
|
|
|
let target = $(event.target);
|
|
|
|
target.addClass("active");
|
|
|
|
if (target.prop("innerText") === "Easy") {
|
|
|
|
current_difficulty = 1;
|
|
|
|
} else if (target.prop("innerText") === "Medium") {
|
|
|
|
current_difficulty = 2;
|
|
|
|
} else {
|
|
|
|
current_difficulty = 3;
|
|
|
|
}
|
|
|
|
change_difficulty(current_difficulty);
|
|
|
|
})
|
|
|
|
|
|
|
|
function change_difficulty(difficulty) {
|
|
|
|
let question = questions[difficulty-1];
|
|
|
|
$("#question-text").text(question["question_text"]);
|
|
|
|
$("#bible-verses").text(question["addresses"]);
|
|
|
|
$("#question-choices").empty();
|
|
|
|
for (let i=0; i< question["answer_list"].length; i++) {
|
|
|
|
let btn = $("<button>")
|
|
|
|
.attr("id", question["question_id"]+"-"+i)
|
|
|
|
.addClass("btn btn-secondary m-1")
|
|
|
|
.text(question["answer_list"][i])
|
|
|
|
.on("click", () => {
|
|
|
|
checkAnswer(question["question_id"], i, question["answer_list"][i]);
|
|
|
|
});
|
|
|
|
if (question.hasOwnProperty("chosen_answer")) {
|
|
|
|
btn.attr("disabled", true);
|
|
|
|
if (question["correct_answer"] === i) {
|
|
|
|
btn.addClass("btn-success");
|
|
|
|
}
|
|
|
|
if (question["chosen_answer"] !== question["correct_answer"] && question["chosen_answer"] === i) {
|
|
|
|
btn.addClass("btn-danger");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$("#question-choices").append(btn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 13:14:29 -07:00
|
|
|
function checkAnswer(question_id, button_index, answer) {
|
2021-08-29 18:56:29 -07:00
|
|
|
let question = questions[current_difficulty-1];
|
|
|
|
question["chosen_answer"] = button_index;
|
2021-04-17 13:14:29 -07:00
|
|
|
let loading_spinner = $("<div>")
|
|
|
|
.attr("id", "check-answer")
|
|
|
|
.addClass("text-center")
|
|
|
|
.text("Checking answer")
|
|
|
|
.append($("<div>")
|
|
|
|
.addClass("spinner-border thin-border ml-1")
|
|
|
|
.attr("role", "status"));
|
|
|
|
$(".question-text:visible").append(loading_spinner);
|
|
|
|
$(`button[id*='${question_id}']`).attr("disabled", true);
|
|
|
|
$.ajax(`{{ url_for("check_answer") }}?question_id=${question_id}&answer=${answer}`, {
|
|
|
|
method: "GET",
|
|
|
|
datatype: "json",
|
|
|
|
success: (data) => {
|
|
|
|
$("#check-answer").remove();
|
|
|
|
if (data[0] === true) {
|
2021-08-29 18:56:29 -07:00
|
|
|
question["correct_answer"] = button_index
|
2021-04-17 13:14:29 -07:00
|
|
|
$("#" + question_id + "-" + button_index).addClass("btn-success");
|
|
|
|
} else {
|
|
|
|
$("#" + question_id + "-" + button_index).addClass("btn-danger");
|
|
|
|
$(`button[id*='${question_id}']`).each((i, element) => {
|
|
|
|
element = $(element);
|
|
|
|
if (element.text() === data[1]) {
|
2021-08-29 18:56:29 -07:00
|
|
|
question["correct_answer"] = i;
|
2021-04-17 13:14:29 -07:00
|
|
|
element.addClass("btn-success");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
2021-03-18 20:08:19 -07:00
|
|
|
{% endblock %}
|