0

I’m making a color guesser. It gives an RGB and multiple choices and you have to guess which one is correct. I made a <div> with grid and put six <div>s there that will be the choices, but when I wrote the following code, the rgb did not work but it did not give any errors.

const colorMap = new Map;
var colorSelector = Math.round(Math.random() * 5);

RandomCreator = () => Math.round(Math.random() * 254);
ColorCreator = (x) => {
  colorMap.set("red" + x, RandomCreator());
  colorMap.set("green" + x, RandomCreator());
  colorMap.set("blue" + x, RandomCreator());
}

for (let count = 0; count < 6; count++) {
  ColorCreator(count);
  document.querySelector('#colors :nth-child(' + (count + 1) + ')').style.backgroundColor = "rgb(" + colorMap.get("+red+" + count) + "," + colorMap.get("+green+" + count) + "," + colorMap.get("blue" + count) + ")";
}
#colors div{
  width: 100px;
  height: 100px;
}
<div id="colors">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
  • 2
    Did you mean `(count + 1)` instead of `count+1`? – Sebastian Simon Dec 23 '22 at 21:03
  • Thanks,but there still another problem! I edited my quetion so you can see it. – josefh weszla Dec 23 '22 at 21:14
  • [What Do You Mean “It Doesn’t Work”?](//meta.stackexchange.com/q/147616/289905) _“It does not work”_ isn’t a problem statement and is meaningless without knowing your _desired_ results and your _actual_ results. If `count` is `1`, then `"+red+" + count` will result in the string `"+red+1"`. Did you mean `"red1"`? Then it’s either `"red" + count` or `\`red${count}\``. – Sebastian Simon Dec 23 '22 at 21:19

0 Answers0