好吧,所以我有一些javascript,基本上它从网站获得一个数学方程式,更改它以便eval()
可读,然后通过eval,然后当我按下一个键时插入从eval()
到inputBox的答案。我有一个问题,(例如)y +? = 20." y"从数字1-20的变化。到目前为止,代码得到了问题的答案,但是以负面形式。 (例如:14 +?= 20 = -14)。所以我需要帮助删除所有" - "我的回答中的人物。
代码变量:
var inputBox = where the answer is (like -14 in my case)
var question = the question. in my case 14 + ? = 20
到目前为止的代码:
//Mathletics Level 4 with Blocks//
function showAnswer(){
var inputBox = document.getElementsByClassName("questions-input-adjustment questions-input-width-v3")[0];
var submitButton = document.getElementsByClassName('question-input-form')[0];
for (var i = 0; i < 100; i++) {
var question = document.getElementsByClassName("questions-text-alignment whiteTextWithShadow question-size-v4")[0].innerText;
question = question.replace('= 20', '-20')
question = question.replace('×', '*')
question = question.replace('=', '');
question = question.replace('=', '');
var answer = eval(question)
inputBox.value = answer;
var awnser = addbits(equasion)
var inputBox = document.getElementsByClassName("questions-input-adjustment questions-input-width-v3")[0];
var submitButton = document.getElementsByClassName('question-input-form')[0];
for (var i = 0; i < 100; i++) {
var question = document.getElementsByClassName("questions-text-alignment")[0].innerText;
question = question.replace('= 20', '-20')
question = question.replace(' =', '');
question = question.replace('×', '*')
question = question.replace('=', '');
inputBox.value = answer;
}
var awnser = addbits(equasion)
document.getElementById('dashow').innerText = awnser;
document.getElementsByClassName("questions-input-adjustment questions-input-width-v3")["0"].value = awnser;
}
window.addEventListener("keydown", checkKeyPressed, false);
function checkKeyPressed(e) {
if (e.keyCode == "81") {
showAnswer()
}
}
答案 0 :(得分:0)
试试这个:
myanswer= myanswer.replace(/-/g,'');
它从答案中反复减去
答案 1 :(得分:0)
你可以使用低于abs功能删除减号
a =-3
x=Math.abs(a);
console.log(x)