2013-04-23 23:27:30 -07:00
|
|
|
function update_board(f, o, s, score) {
|
2013-04-23 22:48:16 -07:00
|
|
|
$("#first").text(f);
|
|
|
|
$("#operation").text(o);
|
|
|
|
$("#second").text(s);
|
2013-04-23 23:27:30 -07:00
|
|
|
$("#score").text(score);
|
2013-04-23 22:48:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function new_problem() {
|
|
|
|
$.get("/api/v0/problem/", function(d) {
|
2013-05-08 23:41:59 -07:00
|
|
|
update_board(d["First"], d["Operation"], d["Second"], d["Score"]);
|
2013-04-23 22:48:16 -07:00
|
|
|
$("#answer").val("");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function deal_with_answer(e) {
|
|
|
|
var data = {
|
|
|
|
"first": $("#first").text(),
|
|
|
|
"operation": $("#operation").text(),
|
|
|
|
"second": $("#second").text(),
|
|
|
|
"answer": $("#answer").val(),
|
|
|
|
};
|
|
|
|
$.post("/api/v0/attempt/", data, function(d) {
|
2013-05-09 00:37:35 -07:00
|
|
|
$("#score").text(d["Score"]);
|
2013-05-09 00:16:54 -07:00
|
|
|
if(d["Status"]) {
|
2013-04-23 23:06:24 -07:00
|
|
|
$("body").removeClass("wrong");
|
2013-04-23 22:48:16 -07:00
|
|
|
new_problem();
|
|
|
|
}
|
|
|
|
else {
|
2013-04-23 23:06:24 -07:00
|
|
|
$("body").addClass("wrong");
|
|
|
|
$("#answer").val("");
|
2013-04-23 22:48:16 -07:00
|
|
|
}
|
2013-04-23 23:06:24 -07:00
|
|
|
$("#answer").focus();
|
2013-04-23 22:48:16 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
new_problem();
|
2013-04-23 23:06:24 -07:00
|
|
|
$("#answer").keypress(function(e) {
|
|
|
|
if( e.which == 13) {
|
|
|
|
deal_with_answer(e);
|
|
|
|
}
|
|
|
|
});
|
2013-04-23 22:48:16 -07:00
|
|
|
});
|