Skip to content

Instantly share code, notes, and snippets.

@Ifycode
Created August 1, 2020 03:22
Show Gist options
  • Save Ifycode/1c7b8542805da5529eb43f48b64a9d95 to your computer and use it in GitHub Desktop.
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
'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