So im trying to make a color guessing game So i created a function that generates a color and returns it, which works fine But since i have 3 buttons with #hex code on them 1 button has to be a correct answer and correct #hex has to be displayed in a color box
So im trying to put 3 #hex codes in each button and choose randomly which #hex code is the correct one and display it in HTML
i know the code is very bad but i still got a long way to go...
function randomColor(){
let randomColor = Math.floor(Math.random()*16777215).toString(16);
return randomColor
}
function arrayOfColors(){
let randColorArr = []
}
function generateColors(){
colorBox.style.backgroundColor = `#${correctColor}`
btn.forEach(button => button.innerHTML = `#${randomColor()}`)
}
generateColors()
randomColorwill generate invalid colors (with a length other than 6 or 3) with a ~6% chance. You are missing.padStart(6, '0')in your color generation. Also, it will never be able to generateffffffbecause you used16777215as exclusive upper bound instead of16777216(which would have been easier to understand in my opinion as0x1000000or1 << 24or2 ** 24by the way)