From 84de8f57805a25756456679fcc0c7b6e67cb8afb Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Thu, 18 Feb 2016 01:13:45 +0000 Subject: [PATCH] Radical answers are now stripped of "-" characters. --- static/quiz_item.coffee | 12 ++++++++---- static/quiz_item.js | 22 +++++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index 4c0516a..efdb116 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -106,13 +106,17 @@ $(document).keypress (e) -> $("#submit-answer").click (e) -> e.preventDefault(); - input_answer = document.getElementById('kana').value; if($("#kana").hasClass("correct")) refreshQuestion(); - else if(selection['answer'].split(/[,\.]/g).map((x) -> x.trim()).indexOf(input_answer) != -1) - $("#kana").addClass("correct").removeClass("wrong"); else - $("#kana").addClass("wrong").removeClass("correct").val('') + input_answer = document.getElementById('kana').value; + expected_answer = selection['answer'].split(/[,\.]/g).map((x) -> x.trim()) + if(selection["item_type"] == "radical") + expected_answer = expected_answer.map((x) -> x.replace("-", " ")) + if(expected_answer.indexOf(input_answer) != -1) + $("#kana").addClass("correct").removeClass("wrong"); + else + $("#kana").addClass("wrong").removeClass("correct").val('') $("#get-help").click (e) -> e.preventDefault(); diff --git a/static/quiz_item.js b/static/quiz_item.js index 4d869cb..a8eb283 100644 --- a/static/quiz_item.js +++ b/static/quiz_item.js @@ -155,17 +155,25 @@ }); $("#submit-answer").click(function(e) { - var input_answer; + var expected_answer, input_answer; e.preventDefault(); - input_answer = document.getElementById('kana').value; if ($("#kana").hasClass("correct")) { return refreshQuestion(); - } else if (selection['answer'].split(/[,\.]/g).map(function(x) { - return x.trim(); - }).indexOf(input_answer) !== -1) { - return $("#kana").addClass("correct").removeClass("wrong"); } else { - return $("#kana").addClass("wrong").removeClass("correct").val(''); + input_answer = document.getElementById('kana').value; + expected_answer = selection['answer'].split(/[,\.]/g).map(function(x) { + return x.trim(); + }); + if (selection["item_type"] === "radical") { + expected_answer = expected_answer.map(function(x) { + return x.replace("-", " "); + }); + } + if (expected_answer.indexOf(input_answer) !== -1) { + return $("#kana").addClass("correct").removeClass("wrong"); + } else { + return $("#kana").addClass("wrong").removeClass("correct").val(''); + } } });