Q:

How to stop random color from repeating?

the title changes color randomly when clicked but it repeates the same color often (I don't want it to repeat the same color in the array twice in a row). I tried to fix this with an if statement but im not sure why it didn't work.

var title = document.querySelector(".title");

function changeColor() {
  let newArray = ["DarkSalmon", "LightSalmon", "Crimson", "Red",
    "DeepPink", "YellowGreen", "GhostWhite"
  ];
  let random = Math.floor(Math.random() *
    Math.floor(newArray.length - 1));
  console.log(random);
  if (title.style.color !== newArray[random]) {
    title.style.color = newArray[random];
  }

}

title.addEventListener("click", changeColor);
<h1 class='title'>Berserk</h1>

A:

If don't want colors to get repeated in a row, you could just add an else statement to your if statement.
I found the error! It's in the capitalization of your color names... Change them to all lowercase and it will magically

var title = document.querySelector(".title");

function changeColor() {
  let newArray = ["darksalmon", "lightsalmon", "crimson", "red", "deeppink", "yellowgreen", "ghostwhite"];
  let random = Math.floor(Math.random() * Math.floor(newArray.length - 1));
  if (title.style.color != newArray[random]) {
    title.style.color = newArray[random];
    console.log(title.style.color);
  } else {
    changeColor();
  }
}

title.addEventListener("click", changeColor);
<h1 class='title'>Berserk</h1>

