I'm working on a code that generates random numbers for 3 columns and checks if each generated number exceeds +5/-5 of its previous number. However, I've encountered an issue where the first two columns always have the "blink" CSS applied to them, even when the generated number falls within the specified range. You can view my code on JSFiddle here: https://jsfiddle.net/d5ykog23/
Here is the code snippet:
var x = document.getElementById("tableContainer");
var i;
var n = 0;
var m;
$("#genNum").click(function(){
for(j = 0; j < x.rows[1].cells.length; j++){
m = x.rows[1].cells[j].innerHTML;
i = Math.random() * (20 - 1) + 1;
x.rows[1].cells[j].innerHTML = Math.round(i);
n = x.rows[1].cells[j].innerHTML
if (!((+m - 5) < n && (+m + 5) > n)) {
$("#tableContainer th:nth-child(" + j + "), #tableContainer td:nth-child(" + j + ")").addClass("blink");
}
}
});
In addition, I have a question about removing the "blink" class from the entire table. I attempted the following code without success:
$("#stopAlarm").click(function(){
$("#tableContainer").removeClass("blink");
});