Lite Brite .toggle-blink not working


#1

hi there
[project https://www.codecademy.com/en/courses/learn-javascript/projects/lite-brite]
not sure why the following code is not working correctly for me. it would be a big help if you can find the errors...
the problems seem to be connected to the last section the $(.toggle-blink) because this causes everything else to stop functioning. nothing happens / is active in the browser with this code.
however, if I comment this $(.toggle-blink) function out of the code then the rest works ok.

function main () {
  var colorClass = '';
  $('.select-color').on('click', function() {
    var selectedColor = $(this).attr('class');
    switch (selectedColor) {
      case 'select-color cyan not-selected':
        colorClass = 'cyan';
        break;
      case 'select-color yellow not-selected':
        colorClass = 'yellow';
        break;
      case 'select-color magenta not-selected':
        colorClass = "magenta";
        break;
                         }
    $(this).removeClass('not-selected');
    $(this).siblings().addClass('not-selected');
  })
  
  $('.box').on('click', function() {
    $(this).toggleClass(colorClass);
  })
  
  $('.toggle-blink').on('click', function() {
    if (colorClass) {
      $('.toggle-blink').toggleClass('opacity');
      setInterval(function() {
        $('.box.magenta .box.yellow .box.cyan').toggleClass('blink');
      }, 350);
    }
  }
}

$(document).ready(main);

#2

This topic was automatically closed after 7 days. New replies are no longer allowed.