If you check the “Application” tab of your browser console, you’ll notice a series of [object Object]. This is because everything you save in localStorage needs to be in string format.
To resolve the issue, wrap the data you’re saving in the JSON.stringify() method. Then, check local storage again to observe the results.
I’ve tried this localStorage.setItem.JSON.stringify(("data", myTaskArr));
and this localStorage.setItem("data",JSON.stringify( myTaskArr));
and this localStorage.setItem("data", myTaskArr).JSON.stringify;
and many variations of these.
What’s the correct way to do it? I think this lesson should be redone with clear instructions. It’s ridiculous that it expects us to know how to do it when it’s the first time we’ve ever heard of JSON.stringify.
the “data you’re saving” that they are referring to is the myTaskArr variable.
So they want you to wrap that variable (in the original code of this step) in a JSON.stringify() method call so you can read it.
That means they want you to replace the myTaskArr variable with a call to JSON.stringify() and pass it the myTaskArr which is the JSON code we are ‘stringifying’.
I’m not sure explaining JSON.stringify() would change anything. As long as you understand the data must be saved in a string format and that the data is the second argument to localStorage.setItem() it should make enough sense.
Once I reset it, I wasn’t able to copy-paste the above code. That returned an error for some reason. And there were red squigly underlines (representing typos) before and after “data”. It threw the error :
Your localStorage.setItem() should have a key of “data”
Even though it did have the key of data. So I reset it again, and then this time only changed the part after the comma. Then it worked. I think there might be a bug in the checking software.
I see the difference in your post. But I don’t know what causes them to be straight or curly. It’s the same key press, right? The key to the right of colon/semi-colon.
I believe the quotes should appear correctly when typed normally in the editor. They should appear straight in any cause, if they are curved you can see it.
When you copy/paste code into the forum without backticks or formatting as code, the forum will translate those into the wrong kind of quotes, which can cause confusion. If that code is then copied back into your editor, you now have the wrong quotes.
Thanks for answering my two questions! So I definitely didn’t type curly quotes into my code myself. Maybe it was from copying code on the forum (which I think I did after it not working a few times). But I also find that unlikely, because when typed in the FCC editor, they get underlined with a red squigly. But it’s good to know this stuff for the future, so thanks again.