+ 3

Fill in the blanks to clear all values stored in the localStorage. Then store "a" using the key "b"?

localStorage.clear (); localStorage. setItem("a" , "b" ); The top is my code why does it not work?

25th Dec 2016, 1:11 AM
Saul
Saul  - avatar
10 Réponses
+ 4
I got the answer it is localStorage.clear (); localStorage. setItem("b" , "a" ); Why is it "b" before "a" I thought the order did not matter since it did not state it in the question.
25th Dec 2016, 1:18 AM
Saul
Saul  - avatar
+ 4
Parameters of setItem() function have an important order: localStorage.setItem(key,value); So, when you getItem(): value=localStorage.getItem(key); However, this isn't the reason for the code don't work... I suppose you have tested it in code playground, isn't it? Because I have tested in code playground ( tablet, android, chrome ), where an exception is raised, then in "real" situation ( means in local, desktop, firefox ), where all is alright ^^ I deduce that there is a problem with how code playground manage, or with the localstorage on android/chrome... but anyway in your code :)
25th Dec 2016, 1:38 AM
visph
visph - avatar
+ 3
More probably a question of authorization: localstorage, by definition, is local relative to the client side ( user ), not to the server side ^^
25th Dec 2016, 1:42 AM
visph
visph - avatar
+ 2
You must see the order of the arguments of the function before use it
25th Dec 2016, 1:27 AM
R P
R P - avatar
+ 2
Yes, still... I'll test in browsers ( desktop and android: I haven't precised that I was use the app ^^ )
25th Dec 2016, 1:51 AM
visph
visph - avatar
+ 2
There's no problem with browser android, so the problem's only on the app... probably an authorization in android! The error message: "Serrurity Error not detected: Failed to read the 'localStorage' property in 'Window': Access is denied for this document."
25th Dec 2016, 1:57 AM
visph
visph - avatar
0
Maybe there is no localStorage on playground
25th Dec 2016, 1:39 AM
R P
R P - avatar
0
It's relative to the navigator. Are you still having problem using localStorage in playground?
25th Dec 2016, 1:47 AM
R P
R P - avatar
0
Must be a problem with permissions in app. Mobile devices are more problematic than browsers ever ^^
25th Dec 2016, 2:08 AM
R P
R P - avatar
0
This is because the data is stored in key/value pairs: with the pair having the key as the initial entry. The question had stated the need to use the key "b" to store the value "a".
5th Jan 2017, 5:59 PM
Nkosivile Mamba
Nkosivile Mamba - avatar