+ 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 Answers
+ 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