Parsing Pensum to html and veryfing it works just fine

This commit is contained in:
Sergiusz Warga 2020-11-23 02:44:15 +01:00
parent 587fe18606
commit 7165defd03
3 changed files with 27 additions and 7 deletions

View File

@ -16,21 +16,41 @@
});
}
function mapper(char) {
var mapper = { 'A': 'Ā',
'a': 'ā',
'E': 'Ē',
'e': 'ē',
'I': 'Ī',
'i': 'ī',
'O': 'Ō',
'o': 'ō',
'U': 'Ū',
'u': 'ū'};
return mapper[char[0]];
}
function input_to_macron(input) {
return input.replace(/(\w)\1/, mapper);
}
function validate() {
const forms = document.querySelectorAll('form');
const form = forms[0];
Array.from(form.elements).forEach((input) => {
console.log(input);
if (input.type=="text" && input.value != input.dataset.expected) {
is_double_ok = (input_to_macron(input.value) == input.dataset.expected);
is_macron_ok = (input.value == input.dataset.expected);
if (input.type=="text" && !(is_double_ok || is_macron_ok)) {
input.setAttribute("style", "border-color:red");
console.log('incorrect!')
console.log('expected: ' + input.dataset.expected);
console.log('input: ' + input_to_macron(input.value));
} else if (input.type=="text") {
input.setAttribute("style", "border-color:green");
}
});
console.log('dupa');
return false;
}
</script>

View File

@ -1 +1 @@
Ni-ilus fluvi_us_ est. Ni-ilus et Rhe-enus fluvi_i-i_ _sunt_, Cre-eta i-insul_a_ _est_. Cre-eta et Rhodus i-insul_ae_ sunt. Brundisium oppid_um_ _est_. Brundisium et Tu-usculum oppid_a_ sunt.
Ni-ilus fluvi_us_ est. Ni-ilus et Rhe-enus fluvi_i-i_ _sunt_. Cre-eta i-insul_a_ _est_. Cre-eta et Rhodus i-insul_ae_ sunt. Brundisium oppid_um_ _est_. Brundisium et Tu-usculum oppid_a_ sunt.

View File

@ -1 +1 @@
Nīlus fluvi<input type="text" data-expected="us" required/> est. Nīlus et Rhēnus fluvi<input type="text" data-expected="ī" required/> <input type="text" data-expected="sunt" required/>, Crēta īnsul<input type="text" data-expected="a" required/> <input type="text" data-expected="est" required/>. Crēta et Rhodus īnsul<input type="text" data-expected="ae" required/> sunt. Brundisium oppid<input type="text" data-expected="um" required/> <input type="text" data-expected="est" required/>. Brundisium et Tūsculum oppid<input type="text" data-expected="a" required/> sunt.
Nīlus fluvi<input type="text" data-expected="us" required/> est. Nīlus et Rhēnus fluvi<input type="text" data-expected="ī" required/> <input type="text" data-expected="sunt" required/>. Crēta īnsul<input type="text" data-expected="a" required/> <input type="text" data-expected="est" required/>. Crēta et Rhodus īnsul<input type="text" data-expected="ae" required/> sunt. Brundisium oppid<input type="text" data-expected="um" required/> <input type="text" data-expected="est" required/>. Brundisium et Tūsculum oppid<input type="text" data-expected="a" required/> sunt.