diff --git a/js/script.js b/js/script.js index 803c165..9cc23b3 100644 --- a/js/script.js +++ b/js/script.js @@ -1,12 +1,11 @@ //Choose a random color -const button = document.querySelector('button') -const body = document.querySelector('body') -const colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'] +const button = document.querySelector("button"); +const body = document.querySelector("body"); -body.style.backgroundColor = 'violet' -button.addEventListener('click', changeBackground) +changeBackground(); +button.addEventListener("click", changeBackground); -function changeBackground(){ -const colorIndex= parseInt(Math.random()*colors.length) -body.style.backgroundColor = colors[colorIndex] +function changeBackground() { + const h = parseInt(Math.random() * 360); + body.style.backgroundColor = `hsl(${h}, 60%, 45%)`; }