Article From:https://www.cnblogs.com/liuwujiang/p/9063934.html
Running environment node.js
 
const readline = require(‘readline-sync’);
let num = 0;
let users = [[‘liuwujiang’, ‘659’], [‘yingyingying’, ‘111’], [‘1’, ‘1’]];
let isOk = true;
let userName, password;
while (true) { //Judge whether or not to quit
while (true) { //Judge whether logon is successful or not
console.log(‘1’ + ‘.’ + ‘ ‘ + ‘Log in ‘);
console.log(‘2’ + ‘.’ + ‘ ‘ + ‘Registration ‘);
console.log(‘Please choose (1-2): ‘)
let sel = readline.question();
if (sel === ‘1’) {
console.log(“Please enter the name of the username: “);
userName = readline.question();
console.log(“Please enter the password: “);
password = readline.question();

let islogin = false;
for (let i = 0; i < users.length; i++) {
if (users[i][0] == userName && users[i][1] == password) { //Determine whether there is a matching data in an array users
console.log(‘Login success, welcome you.
islogin = true;

}
}

if (islogin == false) {
num++; //Recording the number of logon errors
if (num >= 3) {
console.log(‘Password error three times, lock hiccup ~ ‘;
isOk = false;
break;
}
else {
isOk = false;
console.log(‘Login failed, please log in again.
}

}
else {
isOk = true;

}
}

else if (sel === ‘2’) {
console.log(“Please enter the name of the username: “);
let userName1 = readline.question();
console.log(“Please enter the password: “);
let password2 = readline.question();
let repeatUserName = false; //Used to judge whether the username is repeated
for (let i = 0; i < users.length; i++) {
if (users[i][0] == userName1) { //Judge whether the username is repeated
console.log(‘There is a username, please reregister ‘).
repeatUserName = true;

}
}
if (repeatUserName == false) {
users.push([userName1, password2]);
console.log(‘The registration is successful, welcome you.
}
isOk = false; //Return loop

}
else
console.log(‘Input error, please enter the number of 1-2 between ‘).

if (isOk) { //To determine whether all the above information is correct is to terminate the cycle.
break;
}
}
if (isOk == false) //Determines whether the card is locked, or if it is locked, the whole procedure is terminated.
{
break;
}
let saveMoney = 0, takeMoney = 0, smile = 0, getMoney, tempMoney;
while (true) { //Repeated selection according to demand
console.log(‘1’ + ‘.’ + ” ” + “Deposit “);
console.log(‘2’ + ‘.’ + ” ” + “Take money “);
console.log(‘3’ + ‘.’ + ” ” + “Look at the balance “);
console.log(‘4’ + ‘.’ + ” ” + “Modify the password “);
console.log(‘5’ + ‘.’ + ” ” + “Exit “);
console.log(“Please choose (1-5): “);
let changepsdOk = true;
let sel2 = readline.question();
switch (sel2) {
case ‘1’: {

console.log(“Please enter the deposit amount (yuan): “);
getMoney = readline.question();
saveMoney += getMoney – 0;
if (getMoney > 10000) { //Judge whether the deposit is > 10000, funny ~
console.log(‘Tuhao, let’s be friends! ‘)
}
break;
}

case ‘2’: {
console.log(“Please choose the amount of money (yuan).
takeMoney = readline.question();
tempMoney = saveMoney; //Temporary storage deposits, convenient withdrawals > revaluation when saving.
saveMoney -= takeMoney;
if (takeMoney > 5000) {
console.log(‘At one time, only 5000 yuan can be taken at most, please rechoose ‘).
break;
}
else {
if (saveMoney < 0) { //Whether the balance is &lt after the withdrawal; 0
smile++; //Record amount > deposit times
if (smile == 2) {
console.log(‘Don’t press it, it’s not your lucky number.
saveMoney = tempMoney;
break;
}
else if (smile == 3) {
console.log(‘Tut Tut, admit that it is so difficult to be poor.
saveMoney = tempMoney;
break;
}
else if (smile > 3) {
console.log(‘Forget it, you’re happy – \ \ \ \ ‘).
saveMoney = tempMoney;
break;
}

else {
console.log(‘How much money do you have in your heart? “);
saveMoney = tempMoney;
console.log(‘Your balance is: ‘+ tempMoney +’);
break;
}
}
}
}
case ‘3’: {
console.log(‘Your balance is’ + saveMoney + ‘).
break;

}
case ‘4’: {
while (true) {
console.log(‘Please enter the modified password: ‘)
let changepsw = readline.question();
console.log(‘Please confirm the modified password: ‘)
let truepsw = readline.question();
if (changepsw == truepsw) {
for (let i = 0; i < users.length; i++) {
if (users[i][0] == userName) {
users[i][1] = changepsw;
console.log(‘Revise the password successfully, please log in again.
changepsdOk = true;

}
}
}
else {
console.log(‘The two password input is not consistent, please reenter ‘).
changepsdOk = false;
readline.question();

}
if (changepsdOk) { //To determine whether the password modification is successful, the current while cycle is terminated successfully.
break;
}
}
}
case ‘5’: {
isOk = false;
break;
}
default: {
console.log(‘Input error, please enter the number of 1-5 between ‘).
}
if (changepsdOk == true) { //To determine whether the password modification is successful, the current while loop is successfully terminated, and the login is re registered.
break;
}
}
readline.question();
if (!isOk) { //Decide whether to choose 4. exit
break;
}
}
}
Link of this Article: JS makes a fake bank withdrawal ATM

Leave a Reply

Your email address will not be published. Required fields are marked *