0

I am making a scratchcard game and I need to know how to check if everything is cleared to go to the next page. i will show u a part of the code i have

i got nine of these scratch pads and i want to go to the other page when they are cleared all nine:

    var images = [], 
        index = 0;

        images[0] = "images/slide1.jpg";
        images[1] = "images/slide2.jpg";
        images[2] = "images/slide3.jpg";
        images[3] = "images/logo.jpg";
        images[4] = "images/winner.png";
        images[5] = "images/scratch-to-win.png";

        index = Math.floor(Math.random() * images.length);

        $('#nummer9').wScratchPad({
          scratchMove: function (e, percent) {
            console.log(percent);
            if (percent > 70)
            {
                this.clear();
            }
          }
        });
        $("#nummer9").wScratchPad('bg', images[index]);
        $("#nummer9").wScratchPad('fg', 'images/overlay.png');
        $("#nummer9").wScratchPad('size', '15');
        $("#nummer9").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

And i need to know what i have to put inside this if statement.

    if ()
        {
            window.alert('alle vakjes zijn open gekrast');
            window.location.href="geenprijs.php";
        }
braX
  • 11,506
  • 5
  • 20
  • 33
Bramos
  • 69
  • 9

1 Answers1

0
    var images = [], 
    var cleared = 0;
    index = 0;

    images[0] = "images/slide1.jpg";
    images[1] = "images/slide2.jpg";
    images[2] = "images/slide3.jpg";
    images[3] = "images/logo.jpg";
    images[4] = "images/winner.png";
    images[5] = "images/scratch-to-win.png";

    index = Math.floor(Math.random() * images.length);

    $('#nummer9').wScratchPad({
      scratchMove: function (e, percent) {
        console.log(percent);
        if (percent > 70)
        {
            this.clear();
            cleared++;
        }
      }
    });
    $("#nummer9").wScratchPad('bg', images[index]);
    $("#nummer9").wScratchPad('fg', 'images/overlay.png');
    $("#nummer9").wScratchPad('size', '15');
    $("#nummer9").wScratchPad('cursor', 'url("./images/coin.png") 5 5, default');

Then

    if (cleared === 9)
    {
        window.alert('alle vakjes zijn open gekrast');
        window.location.href="geenprijs.php";
    }
Keith.Abramo
  • 6,952
  • 2
  • 32
  • 46
  • You might need to store the 'cleared' variable in a more global scope where it can be used statically across all your wScratchPads. Without seeing how you define all of your wScratchPads it would be hard to tell you exactly where it needs to go. – Keith.Abramo Sep 10 '14 at 14:56