From 1c14ef6c9165cd4f89ae1113af7590c90fe0edb0 Mon Sep 17 00:00:00 2001 From: gaizkamg <57919401+gaizkamg@users.noreply.github.com> Date: Fri, 13 Nov 2020 19:48:34 +0100 Subject: [PATCH] Update script.js The length of the array wil be -1 the order of the array. Array order 0-5, array lenght 6. So Math.random()*colors.length+1 will drop some undefined positions. --- Change_Color_Background/js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Change_Color_Background/js/script.js b/Change_Color_Background/js/script.js index ea46b78..750a2e7 100644 --- a/Change_Color_Background/js/script.js +++ b/Change_Color_Background/js/script.js @@ -7,6 +7,6 @@ body.style.backgroundColor = 'violet' button.addEventListener('click', changeBackground) function changeBackground(){ -const colorIndex= parseInt(Math.random()*colors.length+1) +const colorIndex= parseInt(Math.random()*colors.length-1) body.style.backgroundColor = colors[colorIndex] }