Open IsuruAbeyrathna opened 3 years ago
Try this:
After the checkAnswer: function(e) ... about line 303:
Add this: (usinjg underscore _uniq function
// ADDED! check the solved array against the original puzzle data entries
var uniqSolved = _.uniq(solved);
console.log(uniqSolved);
var numMatches = 0;
var numMatchedAll = 0;
for(var i=0; i < puzz.data.length; i++) { // look through all entries
numMatchedAll++;
for(var a=0; a < solved.length; a++) {
var puzzItem = puzz.data[i];
var puzzAnswer = uniqSolved[a];
if(puzzAnswer === puzzItem.answer) {
numMatches++;
}
}
};
if(numMatches === numMatchedAll) {
console.log("puzzle solved!!!!!!!");
} else {
console.log("not yet ...");
}
Up to you what to do when puzzle solved
Thank you so much!
Please can someone says how to add a winning message after the puzzle completed? Thank you!