具体代码如下所述:
const readline = require('readline-sync')//引用readline-sync let arr = [['zhang', '123', 2000], ['yang', '123456', 3000]]; //登陆 let add = function () { let s = 2;//输入错误的次数 while (true) { console.log('请输入用户名:'); let user = readline.question(); console.log('请输入密码:'); let password = readline.question(); for (let i = 0; i < arr.length; i++) { if (user === arr[i][0] && password === arr[i][1]) { console.log('欢迎你,登陆成功'); mean(i); return; } } //输入不正确,超过三次 if (s != 0) { console.log(`密码或账户有误,你还有${s}次机会,请重新输入!`); s--; } else { console.log('对不起,账户锁定!'); break; } } } //存款 let fn1 = function (i) { console.log('存款'); console.log('请输入存款金额:'); let cunkuan = readline.question() - 0; arr[i][2]+= cunkuan; console.log('系统正在为你存钱请稍等。。。。。\n存钱成功您当前余额为' + arr[i][2]); } //取款 let fn2 = function (i) { console.log('取款'); console.log('请输入取款金额:'); let qukuan = readline.question() - 0; if (qukuan > arr[i][2]) { console.log('对不起你的余额不足!,请重新输入金额或者退出'); } else { arr[i][2] = arr[i][2] - qukuan; console.log('正在为你取钱。。。。。\n您当前余额为:' + arr[i][2]); } } //查看 let fn3 = function (i) { console.log('查看'); console.log('正在查询。。。。\n您当前的余额为:' + arr[i][2]); } //退出 let fn4 = function () { console.log('退出'); console.log('欢迎你下次使用!'); } //流程 let mean = function (i) { for (let yewu = 1; yewu >= 1; yewu++) { console.log('请选择业务:\n1.存款: \n2.取款: \n3.查看: \n4.退出:'); let yewu = readline.question() - 0; switch (yewu) { case 1: fn1(i); continue; case 2: fn2(i); continue; case 3: fn3(i); continue; case 4: fn4(); return; }break; } } add();
总结
以上所述是小编给大家介绍的使用javascript函数编写简单银行取钱存钱流程,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!