My project includes a function that generates three random numbers from the basket and maps each to a button. The idea is that each time you press a button you will get three new numbers and the number you pressed will be removed from the array. However, whenever the startTurn function is called, it spits out the same 3 numbers.
const repeat = (arr, n) => Array(n).fill(arr).flat();
let basket = repeat(["red", "orange", "yellow", "green", "blue", "purple"], 3);
function newGame() {
basket = repeat(["red", "orange", "yellow", "green", "blue", "purple"], 3);
console.log(basket);
startTurn();
}
const button1 = document.querySelector('#button1');
const button2 = document.querySelector('#button2');
const button3 = document.querySelector('#button3');
const button4 = document.querySelector('#new-game');
let turncount = 0;
let choice = [];
function startTurn(){
while(choice.length <= 3){
let r = Math.floor(Math.random() * (basket.length)) ;
if(choice.indexOf(r) === -1) choice.push(r);
}
button1.style.backgroundColor = basket[choice[0]];
button2.style.backgroundColor = basket[choice[1]];
button3.style.backgroundColor = basket[choice[2]];
console.log(basket.length);
console.log(basket[choice])
}