jookr
2023-10-11 11:04:13 +08:00
下边生成的题目马上填结果,马上判断对对错就更好了,给你助力
```
//题目生成
questions.innerHTML += "<p>" + a + ' ' + op + ' ' + b + ' = <input type="number" onkeyup="calculate('+a+",'"+op+"',"+b+',this)" /> </p>';
//判断结果
function calculate(a,op,b,obj){
console.log(a,op,b);
console.log(obj.value);
let result;
switch(op) {
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '÷':
result = a / b;
break;
default:
throw new Error('Unsupported operator');
}
console.log(result);
// return (result==obj.value)?true:false;
if(result!=obj.value){
// obj.className = 'resFail';
obj.style.border = '1px solid red';
}else{
obj.style.border = '';
}
console.log((result==obj.value)?'true':'false');
}
```