+ 1

JS localStorage help.

There’s prompt(“Name please”); User puts in name. And clocks on. Now I want to store that value in a localStorage. So next time user comes back he doesn’t need to enter name again because he has already put a name. https://code.sololearn.com/WR4Blfe3gsmw/?ref=app

15th Jul 2020, 4:04 AM
Ginfio
Ginfio - avatar
3 ответов
+ 3
Ginfio local storage will not work here as you want. It will work on browser. One more thing you declared dslpy inside if statement so you can't access in else statement.
15th Jul 2020, 4:20 AM
A͢J
A͢J - avatar
+ 3
Ginfio Try this on browser var username = prompt("Enter username"); if (username != '') localStorage.setItem("username", username); function displayInfo() { var username = localStorage.getItem("username"); if (username != '') { alert (username); } } window.onload = displayInfo;
15th Jul 2020, 4:29 AM
A͢J
A͢J - avatar
+ 2
AJ Anant ok. thank u. Ill try it
15th Jul 2020, 4:31 AM
Ginfio
Ginfio - avatar