Learn JavaScript - Lite Brite


#1

Here is the link for the project:
https://www.codecademy.com/en/courses/learn-javascript/projects/lite-brite

10.Inside the .box click function, use $(this) to select the box that was clicked, and toggle the class colorClass.
Test it out: you should be able to click a color, then click a box in the grid, and it should change to the selected color!_

On step 10, I can’t display the color on the box, can you help me
Here is my code:

```
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.cyan, .box.yellow, .box.magenta').toggleClass('blink');
      }, 350);
    }
  });
}

$(document).ready(main);
<do not remove the three backticks above>Preformatted text

#2

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