So I'm trying things out. This code should make a useraccount and push the data in an array.
However I cannot seem to run addNewAccount(). It should run automaticly but it doesn't. Probably because i'm doing something wrong. When I type addNewAccount() manually in the console, it returns undefined.
There might be a few bugs since the code is not finished yet but at least addNewAccount() should run right?
//should run code automaticly.
addNewAccount();
let users = [];
function addNewAccount() {
function userName() {
let username = prompt('Enter a new username...');
if (username === '') {
alert('You must enter a username!')
userName()
} else {
passWord();
}
}
function passWord() {
let password = prompt('Now enter a new password. It should contain atleast 5 characters...');
if (password.length < 5) {
alert('Password must be atleast 5 characters long!')
passWord();
} else {
confirm();
}
}
function confirm() {
let userInput = prompt(`Username: ${this.username} and Password: ${this.password}. Is this correct? (Y/N)`).toLowerCase();
if (userInput === 'y') {
function newUser(x, y) {
this.username = x;
this.password = y;
}
let user = new newUser(x, y);
users.push(user);
alert('Account created!');
} else if (userInput === 'n') {
inputN();
function inputN() {
let userInput = prompt('Type one of these commands "1" to change username. "2" to change password.');
if (userInput === '1') {
userNameChange();
function userNameChange() {
let username = prompt('Enter a new username...');
if (username === '') {
alert('You must enter a username!')
userNameChange();
} else {
confirm();
}
}
} else if (userInput === '2') {
passWordChange();
function passWordChange() {
let password = prompt('Now enter a new password. It should contain atleast 5 characters...');
if (password.length < 5) {
alert('Password must be atleast 5 characters long!')
passWordChange();
} else {
confirm();
}
}
} else {
alert('Input invalid! Please use one of the commands...')
confirm();
}
}
}
}
}