+ 1
Hey sololearn code ninjas I need your help in javascript
To understand this code better, enter in a list of two items, like In the first input enter in name: aaa phone: 111 refresh again in the first input enter in Name: bbb phone: 122 In the second input enter in name: ccc phone: 133 for the first input, a list of items is created but it is removed after refreshing the browser for the second input, the items will not be removed but does not create a list Is there any way to unify these two codes into one https://code.sololearn.com/WxORUBGe7b69/?ref=app
4 Respuestas
0
Hey Steve,
Try replacing the code on line 43 with display(), that way you can get rid of the error it is causing and display what is in local storage.
0
oh ha another thing you need to use something like visual studio code cause it won't work on a phone app
0
Steve
I know sololearn doesn't allow access to localstorage when using their android app.
My suggestion is still the same.
To clarify, line 43: appearing.innerHTML = archive;
The variable archive does not have access to the variable archive you defined in the display function.
function display() {
localStorage.setItem(phone.value, name.value);
var archive = [];
for (var i = 0; i<localStorage.length; i++) {
archive[i] = "<br>" + localStorage.getItem(localStorage.key(i));
}
appearing.innerHTML = archive;
}
Variables defined inside a function are not accessible (visible) from outside the function. This is the reason you are getting a Reference Error at line 43. Check the developer's console. for the error.
The error won't stop your code from running.
The function display does exactly what you want line 43 to do, list the current values in localstorage.
Replacing appearing.innerHTML = archive with display(), you will get the results you expected.
0
Alright thanks for your help great explanation as well