Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript DOM Scripting By Example Improving the Application Code Next Steps

Ahmed A
seal-mask
.a{fill-rule:evenodd;}techdegree
Ahmed A
Full Stack JavaScript Techdegree Student 3,832 Points

[solved] localStorage.setItem not working on the js file, but working when typed into the console.

I'm attempting the challenge at the end of the last video of this course, and I have added the following lines of code at the end of my js file. However, when I refresh the page to test it, it turns out that the local storage hasn't been updated. It works as intended only when I type the localStorage.setItem method on the console and refresh the page. let saved = localStorage.getItem('invitedList'); if (saved) { ul.innerHTML = saved; }
localStorage.setItem('invitedList',ul.innerHTML);

1 Answer

Steven Parker
Steven Parker
231,271 Points

This might be an issue of when the data is saved. The script will save it immediately when the page loads, but if some dynamic process is adding content later, a manual save would get it where the script wouldn't.

if that's not it, or you need more help fixing it, make a snapshot of your workspace and post the link to it here.

Ahmed A
seal-mask
.a{fill-rule:evenodd;}techdegree
Ahmed A
Full Stack JavaScript Techdegree Student 3,832 Points

Thanks for your suggestion. I actually solved this issue right after posting this question, turns out there was an error at the submit event listener which prevented program from executing the local storage setItem method.

Steven Parker
Steven Parker
231,271 Points

I suppose you could post your solution as an answer and mark it "best answer". :see_no_evil: