About
Function Window.prompt will prompt you to enter a value with a question
Articles Related
Example
function setUserName(shouldPrompt) {
var myName;
if (shouldPrompt) {
myName = prompt('Please enter your name.');
localStorage.setItem('name', myName);
}
if(!localStorage.getItem('name')) {
myName = 'Anonymous';
} else {
myName = localStorage.getItem('name');
}
var myHeading = document.querySelector('p');
myHeading.textContent = 'Hello ' + myName;
}
setUserName(false);
var myHTML = document.querySelector('button');
myHTML.onclick = function() {
setUserName(true);
}
<p>Hello comes here</p>
<button>Change user</button>