Hi, this is my code. The image gallery seems to be working fine and doing what it’s supposed to do.
I do think I skipped the whole find the current image source using the getAttribute() thing. I’m wondering if it matters as long as the image gallery does what it’s meant to do or if there’s a case where it would mess things up?
Anyway, here is my code:
let displayedImage = document.querySelector(’.displayed-img’);
let thumbBar = document.querySelector(’.thumb-bar’);
btn = document.querySelector(‘button’);
let overlay = document.querySelector(’.overlay’);
/* Looping through images */
for (let i=1; i <= 5; i++) {
let thumbPic = ‘images/pic’+ [i] + ‘.jpg’;
let newImage = document.createElement(‘img’);
newImage.setAttribute(‘src’, thumbPic);
thumbBar.appendChild(newImage);
function bgImage(){
displayedImage.setAttribute(‘src’, thumbPic)
}
newImage.addEventListener(‘click’, bgImage);
}
/* Wiring up the Darken/Lighten button */
btn.onclick = function(){
if (btn.getAttribute(‘class’) === ‘dark’){
btn.setAttribute(‘class’, ‘light’);
btn.textContent = ‘Lighten’;
overlay.style.backgroundColor = ‘rgba(0,0,0,0.5)’
} else {
btn.setAttribute(‘class’, ‘dark’);
btn.textContent = ‘Darken’;
overlay.style.backgroundColor = ‘rgba(0,0,0,0)’
}
}