Eveything works (That´s why I don´t share the full code), but Test 5 keeps failing all the time.
I tried to rewrote it many times, I did the whole Lab 4 times, but test 5. fail is always there.
What I tried so far:
I wrote localStorage.removeItem("bookmarks") for the first line to clear the "bookmarks" data.
Writing a try...catch. (see below)
Resetting the test.
Incognito mode. (browser info below)
I also saved my code, simply wrote localStorage.clear() and then instantly try my code again.
And my code worked every time, but test 5. always fails.
Dev console says: “SyntaxError: Unexpected token ‘i’, “invalid” is not valid JSON”;
I guess it maybe part of the test, to read a string called “invalid” and see how the function works, so I wrote the try...catch method, wich also not fulfilling Test 5.
I think the validation should take place when adding a bookmark, but based on your question I made a lot of changes and you were right that getBookmarks() have to validate the data from localStorage.
My solution logic was: checking if keys exist, than filtering by the "url": key and then filtering for duplicates.
And a try...catch to make sure an array will be always returned.
The last two objects in the console was about checking duplicates. So I made a duplicate filtering in the getBookmarks().
Is this what do you expected from me?
Anyway, thank you very much! Both comment leaded me to the solution, so I don´t know wich one to mark with the solution button.
not really, it was to let you see that you are tested with a bookmark like {name: "example1", category: "news", notUrl: "example1.com"} that has invalid properties, but if it was helpful for you for other ways, that’s great too
I do was checking every single change closely after you told me that, but didn´t see anything unusual in the key and value pairs, until I have red names like “name: duplicate1” in the last two changes.
It was after I made the filtering code of course.
I never think about checking test values in the dev tools console, so I learned a new debug techniqe from you, thank you very much! It is really helpful.
ah yes, that one is for the bookmarks with same name in different categories
but you were busy with the validation, so it would have come later as a suggestion