1. 程式人生 > >JavaScript模擬ATM業務

JavaScript模擬ATM業務

nan AS money pan check let on() 銀行 三次

const readline = require("readline-sync");
let time = 0; //輸密碼次數
let x = 1; //臨時變量
console.log("請輸入您的密碼");
let password = readline.question() - 0;
while (password != 123456) {
    console.log("您輸入的密碼有誤,請重新輸入");
    password = readline.question() - 0;
    time++;
    if (time == 2) {
        console.log("密碼三次錯誤,卡已被鎖定");
        
break; } } //以上為確認密碼正確 if(password == 123456){ let balance = 2000; //默認卡內余額為兩千 while (x == 1) { console.log("請選擇業務"); console.log("1.存款"); console.log("2.取款"); console.log("3.查看"); console.log("4.退出"); let check = readline.question() - 0; while
(isNaN(check) || check < 1 || check > 4) { console.log("請重輸"); check = readline.question() - 0; } if (check == 4) { console.log("感謝使用,再見"); break; } if (check == 3) { console.log(`銀行卡余額為${balance}元`); console.log(
"退出請按1,返回主菜單請按2"); let get = readline.question() - 0; while (isNaN(get) || get < 1 || get > 2) { console.log("請重輸"); get = readline.question() - 0; } if (get == 1) { console.log("感謝使用,再見"); x++; } } while (check == 2) { if (balance == 0) { console.log("請註意,卡裏沒有錢啦"); console.log("退出請按1,返回主菜單請按2"); let choice2 = readline.question()-0; while (isNaN(choice2) || choice2 < 1 || choice2 > 2) { console.log("請重輸"); choice2 = readline.question() - 0; } if (choice2 == 1) { console.log("感謝使用,再見"); x++; break; }else{ break; } } console.log("請輸入取款金額:"); let drawmoney = readline.question()-0; while (isNaN(drawmoney) || drawmoney < 0 || drawmoney > 20000) { console.log("單筆取款不得超過兩萬,請輸入正確的數字"); drawmoney = readline.question() - 0; } let h =balance;//臨時變量 while (drawmoney > h) { console.log("取款金額超過余額,請重新輸入"); drawmoney = readline.question()-0; } balance -= drawmoney; console.log(`取款金額為${drawmoney}元,卡內剩余${balance}元`); console.log("退出請按1,繼續取款請按2,返回主菜單請按3"); let choice1 = readline.question() - 0; while (isNaN(choice1) || choice1 < 1 || choice1 > 3) { console.log("請重輸"); choice1 = readline.question() - 0; } if (choice1 == 1) { console.log("感謝使用,再見"); x++; break; }else if(choice1 == 2){ check == 2; }else{ break; } } while (check == 1) { console.log("請輸入存入金額:"); let savemoney = readline.question()-0; while (isNaN(savemoney) || savemoney < 0 || savemoney > 50000) { console.log("單筆存款不得超過五萬,請輸入正確的數字"); savemoney = readline.question() - 0; } balance += savemoney; console.log(`存入金額為${savemoney}元,卡內剩余${balance}元`); console.log("退出請按1,繼續存款請按2,返回主菜單請按3"); let choice = readline.question() - 0; while (isNaN(choice) || choice < 1 || choice > 3) { console.log("請重輸"); choice = readline.question() - 0; } if (choice == 1) { console.log("感謝使用,再見"); x++; break; }else if(choice == 2){ check == 1; }else{ break; } } } }

JavaScript模擬ATM業務