Created
August 1, 2020 03:22
Revisions
-
Ifycode created this gist
Aug 1, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ 'use strict'; const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F']; const section1 = document.querySelector('.section1'); const btn = document.getElementById('btn'); const color = document.querySelector('.color'); let getRandomNumber = () => { return Math.floor(Math.random()*hex.length); } const changeColor = () => { let hexColor = '#'; let i = 0; for (; i < 6; i++) { hexColor += hex[getRandomNumber()]; } color.innerHTML = hexColor; color.style.color = hexColor; section1.style.backgroundColor = hexColor; } changeColor(); //on js file load btn.addEventListener('click', changeColor); //on click