You get the wrong score, because your algorithm does not take into account squares that have already been flipped, as a result, the squares get counted twice.
The easiest way to maintain accurate counts is to use the fact that 'getElementsByClassName' returns a live list of node.
Note: getElementsByClassName has good browser support , but if your browser requirements are different, you need to adjust this a bit.
At the input, initialize the list (the name of the variable is just to distinguish it from the previous name):
var newFlippedCount = document.getElementsByClassName('flipped');
Each time you update a square with a bomb counting class, use this instead (also adds an inverted class):
document.getElementById(boxNum).className = classList[bombCount] + ' flipped';
When you update the user interface with a new counter enabled, use:
document.getElementById("flipped").innerHTML = newFlippedCount.length;
Now your score is magical :)
Note. You can also solve this problem by checking that the window is upside down before increasing flippedCount .
You also occasionally received an error message in the console:
Uncaught TypeError: Cannot set property 'className' of null
on this line (around line: 298):
document.getElementById (boxNum) .className = classList [bombCount];
You should protect this either by checking the bounds, or simply by checking the return value before using it:
var ele = document.getElementById(boxNum); if(!ele) return; ele.className = classList[bombCount] + ' flipped';
Demo
Edit: if you're interested, here is a high-level overview of the Minesweeper Cascade Algorithm
Update - cascade error detected
One of the reasons the cascade does not work correctly in successive repetitions is because the variable used to track cells that have already been set did not get reset in the new game. For correction:
function start() { …
Updated script with additional debugging operations to help find the problem:
Demo