JavaScript と CSS でこのクイズがあります。これは、入力を回答の配列に対してチェックします。RegEx を実装しようとする前は、問題なく動作していました。RegEx を入れて、回答の大文字と小文字を区別しないようにしました。新しいコードは次のとおりです。
function check(a) {
var str=a;
var patt = new RegExp("/"+key[window.questnum]+"/i");
var anscheck=patt.test(str);
if(anscheck==true){
document.getElementById('quiz').style.backgroundColor="#44ee99";
setTimeout(function() {
document.getElementById('quiz').style.backgroundColor="#44aaff";
}, 500);
newquest(); }
else if(a=="") {
document.getElementById('answer').style.backgroundColor="#00eeee";
setTimeout(function() {
document.getElementById('answer').style.backgroundColor="#FFFFFF";
}, 250);
}
else {
document.getElementById('quiz').style.backgroundColor="#ee9944";
setTimeout(function() {
document.getElementById('quiz').style.backgroundColor="#44aaff";
}, 500);
}
古い作業コードは次のとおりです。
function check(a) {
if(a==key[window.questnum]){
[[etc changing color]]
ありとあらゆる助けをいただければ幸いです。