From 0650fec05669607eec283411a7f4b0990d32dfc3 Mon Sep 17 00:00:00 2001 From: Aleksei__developer <84816879+AlekseidDEV@users.noreply.github.com> Date: Mon, 18 Sep 2023 21:55:38 +0300 Subject: [PATCH] Update script.js Previously, this button would stop at the last color and no longer work. Now there is a condition that allows you to change colors indefinitely. --- Background Color Changer/script.js | 37 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Background Color Changer/script.js b/Background Color Changer/script.js index ddb9b49f..677e1c5b 100644 --- a/Background Color Changer/script.js +++ b/Background Color Changer/script.js @@ -1,6 +1,31 @@ -var color= ["#222f3e","#f368e0","#ee5353","#6c55cc","#24ffff","#ff2626","#ffffff","#000000","#7878ff","#cdcdcd","#454545","#909090","#cccddd","#0abde3","#10ac84","#5f27cd"]; -var i=0; -document.querySelector("button").addEventListener("click",function(){ - i=1 { + if (i <= color.length - 2) { + i++; + document.body.style.background = `${color[i]}`; + } else { + i = 0; + document.body.style.background = `${color[i]}`; + } +});