const readline = require('readline-sync'); let arr = [['zhangsan','123456'],['lisi','123456']]; let menu='1.取款\n2.存款\n3.查看\n4.退出'; let isGister=false; //定義初始登陸錯誤 let inputfalse=0; //定義輸入錯誤次數 while(!isGister) { console.log('請輸入賬號:') let username = readline.question(); console.log('請輸入密碼:') let password = readline.question(); for ( i = 0; i < arr.length; i++) { if (username==arr[i][0]&&password==arr[i][1]) { console.log('登陸成功'); let flag=true; let balance=0; while(flag) { console.log(menu); console.log('請選擇:') let item = readline.question()-0; switch (item) { case 1: { let flag1=true; while(flag1) { console.log(`當前餘額爲${balance}元,請輸入取款金額:`) let outmoney = readline.question(); balance-=outmoney; console.log(`取款成功,當前餘額爲${balance}元。`) console.log('繼續取款請按1,返回上一級就按0') let item2 = readline.question()-0; switch (item2) { case 1: break; case 0: flag1=false; } } break;1 } case 2: { let flag1=true; while(flag1) { console.log(`當前餘額爲${balance}元,請輸入存入金額:`) let savemoney = readline.question()-0; balance+=savemoney; console.log(`取款成功,當前餘額爲${balance}元。`) console.log('繼續存款請按1,返回上一級就按0') let item2 = readline.question()-0; switch (item2) { case 1: break; case 0: flag1=false; } } break; } case 3: { console.log(`當前餘額爲${balance}元,請輸入取款金額:`) console.log('返回上一級請按0') let item2 = readline.question()-0; switch (item2) { case 1: break; case 0: flag1=false; } break; } case 4: { console.log('感謝使用!') flag=false; break; } default:console.log('輸入有誤,請從新輸入:') } } isGister=true; } } if(!isGister) { console.log('登陸失敗,請從新登陸'); inputfalse++; } if(inputfalse==3) { console.log('輸入次數過多,鎖卡') break; } }