From 9b17d17a9e0d5dccecba4fcf0f7983c5c9f3a768 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Mon, 5 Oct 2015 12:41:55 +0100 Subject: [PATCH] Added kanji/vocab meaning quiz functionality. --- static/quiz_item.coffee | 11 ++++++++--- wanikaniburned.py | 6 ++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index 122280b..7904e25 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -25,13 +25,18 @@ refreshQuestion = () -> else $("#question-area").text(selection['question']); else - $("#kana").attr("placeholder", "かな") if(selection['item_type'] == 'kanji') document.body.style.backgroundColor = "deeppink"; else document.body.style.backgroundColor = "darkviolet"; - wanakana.bind(input_element); $("#question-area").text(selection['question']); + if(Math.random() >= 0.5) # Random chance of asking for the kana or meaning + $("#kana").attr("placeholder", "Meaning") + $('#answer').text(selection['answer_meaning']); + wanakana.unbind(input_element); + else + $("#kana").attr("placeholder", "かな") + wanakana.bind(input_element); $(document).keypress (e) -> if(e.which == 13) @@ -42,7 +47,7 @@ $("#submit-answer").click (e) -> input_answer = document.getElementById('kana').value; if($("#kana").hasClass("correct")) refreshQuestion(); - else if($('#answer').text().replace(/\s/g, '').split(/[,\.]/g).indexOf(input_answer) != -1) + else if($('#answer').text().split(/[,\.]/g).indexOf(input_answer) != -1) $("#kana").addClass("correct").removeClass("wrong"); else $("#kana").addClass("wrong").removeClass("correct").val('') diff --git a/wanikaniburned.py b/wanikaniburned.py index 1658c55..6c52d04 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -156,9 +156,11 @@ def get_items(): made_answer = item['onyomi'] elif item['kunyomi']: made_answer = item['kunyomi'].replace('.*', '') - items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer}) + items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer, + 'answer_meaning': item['meaning']}) for item in json.loads(current_user.vocabulary): - items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana']}) + items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], + 'answer_meaning': item['meaning']}) return jsonify(item_list=items)