-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lalonggone/feat/Palette-button
Feat/palette button
- Loading branch information
Showing
4 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var currentPalette = []; | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//DOM Elements | ||
var newPaletteButton = document.querySelector(".new-palette-button"); | ||
var colorPaletteSection = document.querySelector('.color-palette'); | ||
var body = document.querySelector('body'); | ||
var paragraphsToChange = document.querySelectorAll('.hex-code'); | ||
var boxesToChange = document.querySelectorAll('.color-box'); | ||
|
||
|
||
//Event Listeners | ||
body.addEventListener('click', function(event) { | ||
if(event.target.className === 'new-palette-button') { | ||
displayHexCode(); | ||
displayColor(); | ||
} | ||
}); | ||
|
||
//Event Handlers and Functions | ||
function getRandomIndex(array) { | ||
return Math.floor(Math.random() * array.length); | ||
} | ||
|
||
function displayHexCode() { | ||
currentPalette = []; | ||
|
||
for (var i = 0; i < paragraphsToChange.length; i++) { | ||
paragraphsToChange[i].innerText = generateHexCode(); | ||
currentPalette.push(paragraphsToChange[i].innerText); | ||
} | ||
} | ||
|
||
function displayColor() { | ||
for (var i = 0; i < boxesToChange.length; i++) { | ||
boxesToChange[i].style.backgroundColor = `${paragraphsToChange[i].innerText}`; | ||
} | ||
} | ||
|
||
|
||
function generateHexCode() { | ||
var hexConditions = [ | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"0", | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9", | ||
]; | ||
var hexColor = ["#"]; | ||
|
||
for (var i = 0; i < 6; i++) { | ||
hexColor.push(hexConditions[getRandomIndex(hexConditions)]); | ||
} | ||
|
||
return hexColor.join(""); | ||
} | ||
|
||
|
||
// Starting Conditions | ||
displayHexCode(); | ||
displayColor(); |
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