Learn JavaScript - Lite Brite


Here is the link for the project:

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';
      case 'select-color yellow not selected':
        colorClass = 'yellow';
      case 'select-color magenta not selected':
        colorClass = 'magenta';
  $('.box').on('click', function() {
  $('.toggle-blink').on('click', function() {
    if (colorClass) {
      setInterval(function() {
        $('.box.cyan, .box.yellow, .box.magenta').toggleClass('blink');
      }, 350);

<do not remove the three backticks above>Preformatted text


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