From 7f109a9214b5caaf6bbd4e3288ca576da533a8d6 Mon Sep 17 00:00:00 2001 From: Brian Ndickers <47857858+bryondickers@users.noreply.github.com> Date: Fri, 27 May 2022 01:35:25 +0300 Subject: [PATCH] arrow function implemented and math,floor used --- js/script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/script.js b/js/script.js index 803c165..4a8d085 100644 --- a/js/script.js +++ b/js/script.js @@ -4,9 +4,8 @@ const body = document.querySelector('body') const colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'] body.style.backgroundColor = 'violet' -button.addEventListener('click', changeBackground) - -function changeBackground(){ -const colorIndex= parseInt(Math.random()*colors.length) +button.addEventListener('click', () => { +const colorIndex = Math.floor((Math.random()*colors.length)) body.style.backgroundColor = colors[colorIndex] } +)