2021-01-22 00:25:31 +01:00
|
|
|
$(function() {
|
|
|
|
document.querySelector("#answer_field").addEventListener("keyup", event => {
|
|
|
|
if (event.key !== "Enter") {return}
|
|
|
|
document.getElementById("correct_answer").style.visibility == "visible" ? document.querySelector("#next_btn").click() : document.querySelector("#answer_btn").click()
|
|
|
|
event.preventDefault()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
function changeQuestion() {
|
|
|
|
document.getElementById("answer_field").value = ""
|
|
|
|
document.getElementById("answer_field").focus()
|
|
|
|
|
2021-01-26 18:04:06 +01:00
|
|
|
let p_one = document.getElementById("character")
|
|
|
|
let p_two = document.getElementById("equivalent")
|
2021-01-22 00:25:31 +01:00
|
|
|
let a = document.getElementById("correct_answer")
|
|
|
|
|
|
|
|
let questionShape = shapeQuestion([document.getElementById('h').checked, document.getElementById('k').checked, document.getElementById('r').checked])
|
2021-01-26 18:04:06 +01:00
|
|
|
if (!questionShape) {return false} // No question can be found if two boxes are left unchecked
|
2021-01-22 00:25:31 +01:00
|
|
|
|
2021-01-27 02:37:57 +01:00
|
|
|
changeBackground(questionShape[1], p_one)
|
|
|
|
changeBackground(questionShape[0], p_two)
|
|
|
|
|
2021-01-22 00:25:31 +01:00
|
|
|
a.style.visibility = "hidden"
|
2021-02-18 16:53:28 +01:00
|
|
|
$("#correct_answer").slideUp(10)
|
2021-01-22 00:25:31 +01:00
|
|
|
|
|
|
|
$.getJSON("characters.json", function(data) {
|
|
|
|
const characters = data.items[Math.floor(Math.random() * data.items.length)]
|
|
|
|
var part_one
|
|
|
|
var part_two
|
|
|
|
var answer
|
|
|
|
|
2021-01-26 18:04:06 +01:00
|
|
|
switch (questionShape[1]) {
|
2021-01-22 00:25:31 +01:00
|
|
|
case "h":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_one = characters.h
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
case "k":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_one = characters.k
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
case "r":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_one = characters.r
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
part_one = "???"
|
|
|
|
}
|
|
|
|
|
2021-01-26 18:04:06 +01:00
|
|
|
switch (questionShape[0]) {
|
2021-01-22 00:25:31 +01:00
|
|
|
case "h":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_two = "hiragana"
|
|
|
|
answer = characters.h
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
case "k":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_two = "katakana"
|
|
|
|
answer = characters.k
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
case "r":
|
2021-01-26 18:04:06 +01:00
|
|
|
part_two = "romaji"
|
|
|
|
answer = characters.r
|
2021-01-22 00:25:31 +01:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
part_two = "???"
|
|
|
|
}
|
|
|
|
|
2021-01-26 18:04:06 +01:00
|
|
|
p_one.innerHTML = part_one
|
|
|
|
p_two.innerHTML = part_two
|
2021-01-27 02:37:57 +01:00
|
|
|
a.getElementsByTagName('p')[0].innerHTML = `the answer was ${answer}`
|
2021-01-22 00:25:31 +01:00
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-27 02:37:57 +01:00
|
|
|
function changeBackground(char, para) {
|
|
|
|
switch (char) {
|
|
|
|
case "h":
|
|
|
|
para.style.backgroundColor = "red"
|
|
|
|
break;
|
|
|
|
case "k":
|
|
|
|
para.style.backgroundColor = "green"
|
|
|
|
break;
|
|
|
|
case "r":
|
|
|
|
para.style.backgroundColor = "blue"
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
para.style.backgroundColor = "black"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 00:25:31 +01:00
|
|
|
function shapeQuestion(allow) {
|
2021-01-26 18:04:06 +01:00
|
|
|
if (allow.filter(Boolean).length < 2) {return false} // No question can be found if two boxes are left unchecked
|
|
|
|
|
2021-01-22 00:25:31 +01:00
|
|
|
let possibilities = ['h', 'k', 'r']
|
|
|
|
var element_one
|
|
|
|
var element_two
|
|
|
|
|
|
|
|
while (element_one == undefined) {
|
|
|
|
let x = Math.floor(Math.random() * possibilities.length)
|
|
|
|
if (allow[x]) {
|
|
|
|
let temp = possibilities[x]
|
|
|
|
allow.splice(possibilities.indexOf(temp), 1)
|
|
|
|
possibilities.splice(possibilities.indexOf(temp), 1)
|
|
|
|
element_one = temp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (element_two == undefined) {
|
|
|
|
let x = Math.floor(Math.random() * possibilities.length)
|
|
|
|
if (allow[x] && possibilities[x] != element_one) {element_two = possibilities[x]}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [element_one, element_two]
|
|
|
|
}
|
|
|
|
|
2021-01-31 18:19:59 +01:00
|
|
|
function checkAnswer() { // Japanese characters are /[\u3040-\u30ff]/ make it so people DON'T try to answer with the wrong alphabet
|
2021-01-22 00:25:31 +01:00
|
|
|
let answer_field = document.getElementById("answer_field")
|
|
|
|
let correct_answer_p = document.getElementById("correct_answer").getElementsByTagName('p')[0]
|
2021-01-27 16:13:40 +01:00
|
|
|
let positive = document.getElementById("positive")
|
|
|
|
let negative = document.getElementById("negative")
|
2021-01-22 00:25:31 +01:00
|
|
|
|
2021-01-27 02:37:57 +01:00
|
|
|
if (answer_field.value.toLowerCase() == correct_answer_p.innerHTML.slice(correct_answer_p.innerHTML.lastIndexOf(" ") + 1)) {
|
2021-02-03 15:36:19 +01:00
|
|
|
positive.style.fontSize = "25px"
|
|
|
|
$("#positive").animate({"fontSize": "20px"}, 250)
|
2021-01-22 00:25:31 +01:00
|
|
|
positive.innerHTML = Number(positive.innerHTML) + 1
|
|
|
|
} else {
|
2021-02-03 15:36:19 +01:00
|
|
|
negative.style.fontSize = "25px"
|
|
|
|
$("#negative").animate({"fontSize": "20px"}, 250)
|
2021-01-22 00:25:31 +01:00
|
|
|
negative.innerHTML = Number(negative.innerHTML) + 1
|
|
|
|
}
|
|
|
|
|
|
|
|
correct_answer.style.visibility = "visible"
|
2021-02-18 16:53:28 +01:00
|
|
|
$("#correct_answer").slideDown(100)
|
2021-01-27 16:13:40 +01:00
|
|
|
|
|
|
|
if (document.getElementById('auto').checked) {changeQuestion()}
|
2021-01-22 00:25:31 +01:00
|
|
|
}
|