1

1-Create an input for the person to type something and when pressing a button Create a Counter

2- A div with a colored background (randomly generate this color so that all counters are not the same)

3- The entire div must be clickable to increment the counter value

-- part 1 and 3 completed, part 2 incomplete

I would like to know if it is possible to create the divs with different colors, I implemented a random color code but it only changes the first div created and leaves the rest blank

as I couldn't post a part of the code on the site I'm leaving a link that shows the complete structure of the code

https://jsfiddle.net/8wz276rj/

rioV8
  • 24,506
  • 3
  • 32
  • 49
gareky1
  • 11
  • 3

1 Answers1

0

if you're only looking for code that generates random color then

const setBg = () => {
  const randomColor = Math.floor(Math.random()*16777215).toString(16);
  document.body.style.backgroundColor = "#" + randomColor;
}

you can later set the div color through this.

buzz
  • 896
  • 2
  • 10
  • 22