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-04-23 23:27:30 -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) {
|
|
|
|
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
|
|
|
});
|