diff --git a/js/script.js b/js/script.js index 803c165..07b35c5 100644 --- a/js/script.js +++ b/js/script.js @@ -1,12 +1,17 @@ //Choose a random color const button = document.querySelector('button') const body = document.querySelector('body') -const colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'] +const hexArr = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'] body.style.backgroundColor = 'violet' button.addEventListener('click', changeBackground) function changeBackground(){ -const colorIndex= parseInt(Math.random()*colors.length) -body.style.backgroundColor = colors[colorIndex] +var hash = '#' +for (let i = 0; i < 6; i++){ +let count = Math.random() * hexArr.length +count = Math.floor(count) +hash += hexArr[count] +} +body.style.backgroundColor = hash }