Created
August 1, 2020 03:22
-
-
Save Ifycode/1c7b8542805da5529eb43f48b64a9d95 to your computer and use it in GitHub Desktop.
Embed for Understanding Regular Function & Converting To Arrow Function Article - First project from 15 javascript project free course transcribed to arrow function
This file contains 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 characters
'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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment