diff --git a/index.html b/index.html
index 98ea0d1..ca489cc 100644
--- a/index.html
+++ b/index.html
@@ -15,27 +15,43 @@
COLORANDOM
-
+
+
+
+
#EA9999
-
+
-
+
+
+
+
#FACB9C
-
+
+
-
+
+
+
+
#FFE59A
-
+
-
+
+
+
+
#B6D7A8
-
+
-
+
+
+
+
#A4C4CA
diff --git a/main.js b/main.js
index 0d8816b..1d96360 100644
--- a/main.js
+++ b/main.js
@@ -1,17 +1,28 @@
//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');
-
+var colorPaletteSection = document.querySelector(".color-palette");
+var body = document.querySelector("body");
+var paragraphsToChange = document.querySelectorAll(".hex-code");
+var boxesToChange = document.querySelectorAll(".color-box");
+var lockedIcon = document.querySelector(".locked-icon");
+var unlockedIcon = document.querySelector(".unlocked-icon");
+var colorBox = document.querySelectorAll(
+ ".box-1, .box-2, .box-3, .box-4, .box-5"
+);
+var box1 = document.querySelector('#box1')
+var box2 = document.querySelector('#box2')
+var box3 = document.querySelector('#box3')
+var box4 = document.querySelector('#box4')
+var box5 = document.querySelector('#box5')
//Event Listeners
body.addEventListener('click', function(event) {
- if(event.target.className === 'new-palette-button') {
- displayHexCode();
- displayColor();
- }
+ if (event.target.className === 'new-palette-button') {
+ displayHexCode();
+ displayColor();
+ }
+
+ toggleLock();
});
//Event Handlers and Functions
@@ -19,22 +30,55 @@ function getRandomIndex(array) {
return Math.floor(Math.random() * array.length);
}
+function toggleLock() {
+ if (event.target.classList.contains('unlocked-icon')) {
+ var parentContainer = event.target.closest('container');
+
+ if (parentContainer) {
+ var lockedIcon = parentContainer.querySelector('.locked-icon');
+ var unlockedIcon = parentContainer.querySelector('.unlocked-icon');
+ var colorSwatch = parentContainer.querySelector('div')
+
+ colorSwatch.classList.add('locked');
+ lockedIcon.classList.remove('hidden');
+ unlockedIcon.classList.add('hidden');
+ }
+}
+
+if (event.target.classList.contains('locked-icon')) {
+ var parentContainer = event.target.closest('container');
+ if (parentContainer) {
+ var lockedIcon = parentContainer.querySelector('.locked-icon');
+ var unlockedIcon = parentContainer.querySelector('.unlocked-icon');
+ var colorSwatch = parentContainer.querySelector('div')
+
+ colorSwatch.classList.remove('locked')
+ lockedIcon.classList.add('hidden');
+ unlockedIcon.classList.remove('hidden');
+ }
+}
+}
+
function displayHexCode() {
- currentPalette = [];
+ currentPalette = [];
- for (var i = 0; i < paragraphsToChange.length; i++) {
- paragraphsToChange[i].innerText = generateHexCode();
- currentPalette.push(paragraphsToChange[i].innerText);
+ for (var i = 0; i < paragraphsToChange.length; i++) {
+ if (!boxesToChange[i].classList.contains("locked")) {
+ 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}`;
+ for (var i = 0; i < boxesToChange.length; i++) {
+ if (!boxesToChange[i].classList.contains("locked")) {
+ boxesToChange[i].style.backgroundColor = `${paragraphsToChange[i].innerText}`;
}
+ }
}
-
function generateHexCode() {
var hexConditions = [
"A",
@@ -63,7 +107,6 @@ function generateHexCode() {
return hexColor.join("");
}
-
// Starting Conditions
displayHexCode();
-displayColor();
\ No newline at end of file
+displayColor();
diff --git a/styles.css b/styles.css
index e646710..97abeeb 100644
--- a/styles.css
+++ b/styles.css
@@ -31,6 +31,9 @@ h1 {
width: 100px;
height: 100px;
border: 4px solid black;
+ display: flex;
+ justify-content: flex-end;
+ align-items: flex-end;
}
.new-palette-button {
@@ -47,6 +50,7 @@ h1 {
}
+
#box1 {
background-color: #ea9999;
}
@@ -66,3 +70,13 @@ h1 {
#box5 {
background-color: #a4c4ca;
}
+
+.locked-icon, .unlocked-icon {
+ height: 20px;
+ margin: 4px;
+}
+
+
+.hidden {
+ display: none;
+}