JavaScript/whack_a_mole/whack_a_mole.js
//after 2 seconds, the picture of a mole turns back into a hole
after 2 seconds, the picture of a mole turns back into a hole
after 2 seconds the picture of a mole turns back into a hole
function pickHole () {
    var holeNumber = (Math.floor(Math.random() * 20) + 1);
    $('#' + holeNumber).html("<img src='mole.jpg'/>").addClass('active');
    setTimeout(function () {
        $('#' + holeNumber).html("<img src='hole.jpg'/>").removeClass('active');
  }, 2000);
    $('#' + holeNumber).click(function () {
        if ($(this).attr('class') === 'active') {
            $(this).html("<img src='hole.jpg'/>").removeClass('active');
            score++;
            $('#scoreCounter').html(score);
        }
    });
}
function pickHole ( ) { var holeNumber = ( Math . floor ( Math . random ( ) * 20 ) + 1 ) ; $ ( '#' + holeNumber ) . html ( "<img src='mole.jpg'/>" ) . addClass ( 'active' ) ; setTimeout ( function ( ) { $ ( '#' + holeNumber ) . html ( "<img src='hole.jpg'/>" ) . removeClass ( 'active' ) ; } , 2000 ) ; $ ( '#' + holeNumber ) . click ( function ( ) { if ( $ ( this ) . attr ( 'class' ) === 'active' ) { $ ( this ) . html ( "<img src='hole.jpg'/>" ) . removeClass ( 'active' ) ; score ++ ; $ ( '#scoreCounter' ) . html ( score ) ; } } ) ; }
after 2 seconds, the picture of a mole turns back into a hole
after 2 seconds the picture of a mole turns back into a hole
//changes image back to a hole and adds score points ONLY when the image on a mole is on