So, here’s where I’m getting stuck: When I click “Darken” button, it darkens the image and then the button changes to “Lighten” (as it should). The problem is, when I click “Lighten” button, it doesn’t actually lighten the picture back to its original state, it just stays dark. Please help me understand the issue with my code. Is there something wrong with my setAttribute command or “if” statements?
What I did was to put both “if” statements under one addEventListener command, instead of having two separate addEventListener commands for each “if” statement.
Hi @George.C,
I m just working through these as well and had the same problem.
So in the code the currentClass is initialised into whatever the class attribute is to begin with. In this case it is dark.
let currentState = btn.getAttribute("class");
The code you created is excellent as it carries out the changes but the currentClass is still initialised with the same value of dark. at the end of each if you need to reinitialise the current class variable so the new class. This means that you put the same code as above without the ‘let’.
Does this make sense?
BTW, great to meet someone who is working through the MDN topics as well. I am on the front end web developer route and this stuff is golden.