-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlatextest.html
71 lines (69 loc) · 2.58 KB
/
latextest.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="jatloesmile-hd.png">
<title>latex test</title>
</head>
<body>
<p>V1.8</p><br>
<p id="test">\(\text{Enter 0 as your answer to start!}\)</p>
<input type="text" placeholder="Answer" id="userAns"> <br> <br>
<button type="button" onclick="doTheThing()">Generate a new problem</button>
<p>Tip: use 3 decimal places for your answer(unless it's an integer, then the website does it for you)! Also, click outside the text box to submit your answer!</p>
</body>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.2.1/math.js" type="text/javascript"></script>
<script>
let ans = "0.000";
document.getElementById("userAns").addEventListener('change', function() {
let daValue = document.getElementById("userAns").value;
if (ans == daValue) {
doTheThing();
}
if (!daValue.includes(".") && daValue != "") {
document.getElementById("userAns").value += ".000";
if (ans == document.getElementById("userAns").value) {
doTheThing();
}
}
});
function doTheThing() {
document.getElementById("userAns").value = "";
let symbols = ["+","-","\\cdot "];
let theThing = "";
let totalNums = 10;
for (let i=0; i<totalNums; i++) {
if (Math.random() < 0.9 || i == totalNums-1) {
theThing += Math.floor(Math.random()*9+1);
if (i!=totalNums-1) theThing += symbols[Math.floor(Math.random()*symbols.length)];
} else {
theThing += "\\frac{" + noFrac(Math.floor((10-i)/2)) + "}{" + noFrac(Math.ceil((10-i)/2)) + "}";
break;
}
}
document.getElementById("test").innerHTML = "Find \\(" + theThing + ".\\)";
let newThingLol = theThing.replaceAll("\\cdot ","*").replaceAll("{","(").replaceAll("}",")");
if (newThingLol.includes("\\frac")) {
newThingLol = newThingLol.substring(0,newThingLol.indexOf(")")+1) + "/" + newThingLol.substring(newThingLol.indexOf(")")+1);
newThingLol = newThingLol.replace("\\frac","");
}
let theAns = math.evaluate(newThingLol);
if (isFinite(theAns) && (!isNaN(theAns))) {
MathJax.typeset();
ans = theAns.toFixed(3);
} else {
doTheThing();
}
}
function noFrac(nums) {
let symbols = ["+","-","\\cdot "];
let theThing = "";
for (let i=0; i<nums; i++) {
theThing += Math.floor(Math.random()*9+1);
if (i!=nums-1) theThing += symbols[Math.floor(Math.random()*symbols.length)];
}
return theThing;
}
</script>
</html>