Learning JavaScript and need some advice. I have a simple piece of code that changes the color of my element when I click it but I want no repeating colours from my array on the onclick event. How would I do this or to help with learning what is the most accepted way of doing this.
Tried using IF statements.
var colors = ["red", "blue", "green", "orange", "purple", "pink"];
document.querySelector('.circle').onclick = function changeColor() {
var rand = colors[Math.floor(Math.random() * colors.length)];
document.querySelector('.circle').style.color = rand;
console.log(rand);
}
I expect the colour to change but not repeat itself.