class DisplayUserDetails{
constructor(userName, password, confirmPassword){
if(userName === null){
// throw new Error("Please enter a valid username")
console.log("this is a null value");
return;
}
this.userName = userName
this.password = password
this.confirmPassword = confirmPassword
}
getUsername(){
// console.log(this.userName)
if (this.userName.length > 10){
console.log(this.userName)
return false
}else{
return true;
}
// console.log(this.userName)
}
getPassword(){
}
confirmPassword(){
}
}
let userName = prompt("Enter your username")
// console.log(userName);
const username = new DisplayUserDetails(userName, "Mbadady123", "Mbadady123")
console.log(username.getUsername());
Now this works but throws an error for the below because null.length is not possible. Is it possible i can just return/end the program if user clicks on the cancel without having an error or without it running any other code inside my class
if (this.userName.length > 10){
console.log(this.userName)
return false