Fixed cloze validation

This commit is contained in:
sergiusz 2021-01-06 02:24:33 +01:00
parent 5a0064827e
commit 72b9a5dbc0

View File

@ -45,11 +45,11 @@
return mapper[char]; return mapper[char];
} }
function input_to_nomacron(input) { function to_nonmacron(input) {
return input.replace(/Ā|ā|Ē|ē|Ī|ī/, macron_to_nomacron); return input.replace(/Ā|ā|Ē|ē|Ī|ī/, macron_to_nomacron);
} }
function input_to_macron(input) { function to_macron(input) {
return input.replace(/(\w)\1/, nomacron_to_macron); return input.replace(/(\w)\1/, nomacron_to_macron);
} }
@ -59,17 +59,19 @@
const inputs = pensum.querySelectorAll('input'); const inputs = pensum.querySelectorAll('input');
inputs.forEach((input) => { inputs.forEach((input) => {
if (input.type=="text" && document.getElementById('vowel_length').checked == false) { if (input.type == "text") {
is_macron_ok = (input.value == input_to_nomacron(input.dataset.expected)); is_nonmacron_ok = false;
is_double_ok = false; is_macron_ok = false;
} else { if (document.getElementById('vowel_length').checked == false) {
is_double_ok = (input_to_macron(input.value) == input.dataset.expected); is_nonmacron_ok = (to_nonmacron(input.value) == to_nonmacron(input.dataset.expected));
is_macron_ok = (input.value == input.dataset.expected); } else {
} is_macron_ok = (input.value == input.dataset.expected);
if (input.type=="text" && !(is_double_ok || is_macron_ok)) { }
input.setAttribute("class", "incorrect"); if (is_nonmacron_ok || is_macron_ok) {
} else if (input.type=="text") { input.setAttribute("class", "correct");
input.setAttribute("class", "correct"); } else {
input.setAttribute("class", "incorrect");
}
} }
}); });