jweisbeck / Crossword

A javascript crossword puzzle script
http://www.jesseweisbeck.com/crossword/
245 stars 140 forks source link

Add a winning Message #22

Open IsuruAbeyrathna opened 3 years ago

IsuruAbeyrathna commented 3 years ago

Please can someone says how to add a winning message after the puzzle completed? Thank you!

bradzo commented 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

IsuruAbeyrathna commented 3 years ago

Thank you so much!