sMilbz
sMilbz

Reputation: 951

Making count reset for each word

In my spelling game there is a grid that is populated with words that are hidden from the user. The aim of the game is to spell these words with the aid of a sound and a picture. The user spells a word by clicking the relevant letters onto the grid.

If the user gets a word wrong the word will glow red. If this happens 3 times then the user will be given the opportunity to move onto the next word with the aid of a button that will appear on the 3rd incorrect attempt.

At the moment this works but I have just come across an error by which the incorrect count carries over. For example if the user gets 2 incorrect attempts on one word then gets it right it moves on to the next. It will then only take one incorrect answer on that word for the user to be given the move on option. Basically I need a way for the count to reset every time it moves on to the next word.

This code counts the number of wrong attempts and then after 3 makes the button (".minibutton") visible.

    var score = {
    right: 0,
    wrong: 0,
    attempts: 0
};

    score.wrong++;

        if (score.wrong == 3) {

            $(".minibutton").css('visibility', 'visible');
            $('.next').css('visibility', 'visible');
         }

A fiddle to help - http://jsfiddle.net/smilburn/7Y7A5/4/ (Sound warning!)

Upvotes: 4

Views: 115

Answers (2)

Johanna Larsson
Johanna Larsson

Reputation: 10761

When the user answers correctly, set score.wrong to 0.

Edit:

As pointed out, you need to handle the case where the user skips the question after incorrectly answering, so a better place to reset the score.wrong value is when you show a new picture, rather than when they answer correctly.

Upvotes: 3

Christoph
Christoph

Reputation: 51191

You need to reset score.wrong every time when a new picture is shown regardless if the user answered wrong or correct.

Btw, your code throws some additional errors, you might want to fix them.

Uncaught TypeError: Object # has no method 'show'

Upvotes: 2

Related Questions