Box and Blink


#1

The colors at the top light up but the box and blink functions are not working. Would someone please help!


#2

Please post a link to the exercise. Thanks.


#3

https://www.codecademy.com/courses/learn-javascript/projects/lite-brite


#4

Compare your code to the following spoiler…

  // at top
  var blink;
  // ...

  $('.toggle-blink').click(function(){
    if (colorClass){
      $(this).toggleClass('opacity');
    }
    if ($(this).hasClass('opacity')){
      blink = setInterval(function(){
        $('.box.magenta, .box.yellow, .box.cyan').toggleClass('blink');
      }, 350);
    } else {
      clearInterval(blink);
    }
  });

Note the use of a variable to reference the setInterval function. We need this if we wish to stop the blinking.

Your code differs from mine only in the above. Note the use of if ($(this).hasClass('opacity')). As I recall this took me quite a while to come up with but my memory is not very good since I did this a couple of years ago. Hopefully it will give some ideas and you might even come back with something better still.