function nameBtn(){
var userName = document.getElementById("nameText").value;
var emptyPlace = 0;
if (userName.length < 2) {
emptyPlace = 1;
return emptyPlace
}
if (emptyPlace == 0) {
localStorage.setItem("name", userName );
localStorage.setItem("entered", 1 );
window.location = "UserApp/";
}
if(emptyPlace == 1){
alert("text");
}
}
I have trying to give alert while input field is empty. System can understand that field is empty but if(emptyPlace == 1) is not working help me please
CodePudding user response:
You are returning which means your function ends after the return, there is no need to return there.
if (userName.length < 2) {
emptyPlace = 1;
return emptyPlace
}
Also dont use var, use const and let.