veraldik / display-mode

code that toggles between day/night mode and saves to localStorage
1 stars 0 forks source link

Project Feedback #1

Open veraldik opened 5 years ago

veraldik commented 5 years ago

Build a website that allows the user to switch between day and night color themes and remembers their choice

@egillespie Can you take a look at this? It's hosted here and meets the following criteria:

I am so stuck! I know i'm missing parts of the project but I'm just trying to get the base firgured out right now. Everytime I refresh the page in firefox (using live-server) different things happen with the button. Please help ):

egillespie commented 5 years ago

Hi @veraldik, happy to help! πŸ™‚

First, let's move all of the JavaScript into your mode.js file and use that file in your HTML by adding this line:

<script src="mode.js"></script>

This will give us better ways to troubleshoot if needed.


Another thing I noticed is that I see the following error in the Chrome Devtools console when I click the button on your page:

image

localStorage.remove isn't a function. For this project, you also don't need to worry about clearing anything from localStorage, so go ahead and remove both window.localStorage.remove('theme') statements. That should resolve this error that stops your code from running.


The next thing I recommend is replacing your else if with an else. This way, if anything besides day-theme ever finds its way into localStorage, your code will still switch the theme correctly.


From what I can see, I think the button will work correctly after the above changes. The final part is to set the theme when the page loads by getting the saved theme from localStorage.

To do that, write some code that does the following at the very end of your JavaScript file:

  1. Get the theme from localStorage and put it in a variable
  2. If the variable is null, set the body style to day-theme
  3. If the variable is not null, set the body style to the value of the variable

This should complete the theme requirements. Give these recommendations a try and send some questions my way if you get stuck again. πŸ‘

veraldik commented 5 years ago

Ah, thank you. It finally works haha

egillespie commented 5 years ago

You're welcome! Your code looks and works really well. Nice work incorporating those recommendations and pulling the rest together. I don't have any recommendations for improvement! πŸŽ‰ :shipit: