-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.js
37 lines (28 loc) · 1013 Bytes
/
check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function initfield(num,numname,answers){
//number num
var answerSpan = document.getElementById('answer'+num);// get the box
var answerMathField = MQ.MathField(answerSpan, {
handlers: {
edit: function() {
var enteredMath = answerMathField.latex(); // Get entered math in LaTeX format
correct = checka(enteredMath,num,answers); //display green check if correct
}
}
});
return answerMathField;
}
/*Paste Inline JS here, or include this file from root
(that means <script src="/check.js"></script> in HTML) and paste the above lines in a separate script tag.
*/
//to check the answers!
function checka(l,n, answers){
if (answers.includes(l)){
document.getElementById("answer"+n).style.color="var(--success)";
document.getElementById("tu"+n).style.display="inline";
return true
}
else{document.getElementById("answer"+n).style.color="var(--dark)";
document.getElementById("tu"+n).style.display="none";
return false
}
}