Could someone tell me why my code is not working in Firefox? It's fine in other browsers, but if I type in 1000 in the Cash at Bank cell, it's marking it as an incorrect answer (highlighting in red and displaying the incorrect feedback). The other validation / testing of other cell entries doesn't work either.
function checkAnswers() {
document.querySelectorAll('[data-answer]').forEach(item => {
if (RegExp(item.dataset.answer).test(item.innerText)) {
item.style.backgroundColor = "#e2edde";
item.title = item.dataset.correct;
} else {
item.style.backgroundColor = "#fce9e9";
item.title = item.dataset.incorrect;
}
})
document.getElementById("feedbackdiv").style.display = "inline-block";
document.getElementById("feedback").innerText = "Click in each highlighted cell for more information.";
document.getElementById("feedbackdiv").style.backgroundColor = "rgb(234, 243, 250)";
document.getElementById("checkbutton").style.display = "none";
document.getElementById("retrybutton").style.display = "block";
}
function showFeedback() {
var cell = document.activeElement;
if (cell.style.backgroundColor == "rgb(226, 237, 222)") {
document.getElementById("feedback").innerText = cell.dataset.correct;
document.getElementById("feedbackdiv").style.backgroundColor = "rgb(226, 237, 222)";
}
if (cell.style.backgroundColor == "rgb(252, 233, 233)") {
document.getElementById("feedback").innerText = cell.dataset.incorrect;
document.getElementById("feedbackdiv").style.backgroundColor = "rgb(252, 233, 233)";
}
}
function showSolution() {
document.querySelectorAll('[data-answer]').forEach(item => {
item.style.backgroundColor = "#eaf3fa";
item.innerText = item.dataset.solution;
})
document.getElementById("feedbackdiv").style.display = "inline-block";
document.getElementById("feedback").innerText = "In the answer you can see that Cash at bank has increased by CU1,000 and equity has increased by CU1,000."; document.getElementById("feedbackdiv").style.backgroundColor = "rgb(234, 243, 250)"; document.getElementById("checkbutton").style.display = "none";
document.getElementById("solution").style.display = "none"; document.getElementById("retrybutton").style.display = "block";
}
<table border="1">
<tbody>
<tr>
<th scope="col"> </th>
<th scope="col">Cash at <br> Bank </th>
<th scope="col">Vehicle</th>
<th scope="col">Equipment</th>
<th scope="col">Supplies</th>
<th scope="col">Accounts <br> Receivable </th>
<th scope="col"> </th>
<th scope="col">Accounts <br> Payable </th>
<th scope="col"> </th>
<th scope="col">Otok, Equity </th>
</tr>
<tr>
<td>(6)</td>
<td id="cashanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^(1000|1\,000)$" data-solution="1,000" data-incorrect="Incorrect. We neeed to show that Cash at Bank has increased by CU1,000." data-correct="Well done. Cash at Bank has increased by CU1,000."
onfocus="showFeedback()"></td>
<td id="vehicleanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^$" data-incorrect="Incorrect. This cell should be left blank." data-correct="Well done. This cell should be left blank." onfocus="showFeedback()"></td>
<td id="equipmentanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^$" data-incorrect="Incorrect. This cell should be left blank." data-correct="Well done. This cell should be left blank." onfocus="showFeedback()"></td>
<td id="suppliesanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^$" data-incorrect="Incorrect. This cell should be left blank." data-correct="Well done. This cell should be left blank." onfocus="showFeedback()"></td>
<td id="receivableanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^$" data-incorrect="Incorrect. This cell should be left blank." data-correct="Well done. This cell should be left blank." onfocus="showFeedback()"></td>
<td></td>
<td id="payableanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^$" data-incorrect="Incorrect. This cell should be left blank." data-correct="Well done. This cell should be left blank." onfocus="showFeedback()"></td>
<td></td>
<td id="equityanswer" title="Click in a cell to type your entry" contenteditable="true" data-answer="^(1000|1\,000)$" data-solution="1,000" data-incorrect="Incorrect. We neeed to show that Equity has increased by CU1,000." data-correct="Well done. Equity has increased by CU1,000."
onfocus="showFeedback()"></td>
</tr>
</tbody>
</table>
<div id="feedbackdiv" style="clear: both; padding-left: 15px; padding-right: 15px; display: none; margin-top: 20px;">
<p id="feedback" style="margin-top: 15px;"> </p>
</div>
<p style="margin-top: 20px;">
<button class="btn btn-secondary" id="checkbutton" onclick="checkAnswers()">Check answers</button>
</p>
<p id="retrybutton" style="display: none">
<button onclick="window.location.reload();" class="btn btn-secondary">Retry</button>
</p>
<p id="solution" style="margin-top: 20px;">
<button class="btn btn-secondary" id="solutionbutton" onclick="showSolution()">Show solution</button>
</p>