Hi folks,
I'm trying to play around with localstorage in JavaScript. So from my understanding to save data to local storage I use localstorage.setItem("name", "value"), however am I able to somehow pass a variable to it? For example, what I'm trying to do is when a user makes an input it stores that value into a variable which I then want to store in localstorage so that when they refresh it shows their inputted value. (Note this is merely just practice for me).
I'm trying to play around with localstorage in JavaScript. So from my understanding to save data to local storage I use localstorage.setItem("name", "value"), however am I able to somehow pass a variable to it? For example, what I'm trying to do is when a user makes an input it stores that value into a variable which I then want to store in localstorage so that when they refresh it shows their inputted value. (Note this is merely just practice for me).
JavaScript:
var userInput;
while (userInput !== "Malcolm") {
userInput = prompt("Enter your name!");
localStorage.setItem("name", "value"); // Can I pass the variable userInput?
}
document.write(localStorage.getItem(userInput));