mmg/static/math.js

37 lines
847 B
JavaScript

function update_board(f, o, s) {
$("#first").text(f);
$("#operation").text(o);
$("#second").text(s);
}
function new_problem() {
$.get("/api/v0/problem/", function(d) {
update_board(d["first"], d["operation"], d["second"]);
$("#answer").val("");
})
}
function deal_with_answer(e) {
var data = {
"first": $("#first").text(),
"operation": $("#operation").text(),
"second": $("#second").text(),
"answer": $("#answer").val(),
};
console.log(data);
$.post("/api/v0/attempt/", data, function(d) {
if(d["status"]) {
$("#content").removeClass("wrong");
new_problem();
}
else {
$("#content").addClass("wrong");
}
});
}
$(function() {
new_problem();
$("#check").click(deal_with_answer);
});