VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 网站开发 > JavaScript >
  • JavaScript教程之用javascript编写简单银行取钱存钱流

const readline = require('readline-sync')//引用readline-sync
 2 let arr = [['zhang', '123', 2000], ['yang', '123456', 3000]];
 3 //登陆 
 4 let add = function () {
 5     let s = 2;//输入错误的次数
 6     while (true) {
 7         console.log('请输入用户名:');
 8         let user = readline.question();
 9         console.log('请输入密码:');
10         let password = readline.question();
11         for (let i = 0; i < arr.length; i++) {     
12             if (user === arr[i][0] && password === arr[i][1]) {
13                 console.log('欢迎你,登陆成功');
14                 mean(i);
15                 return;
16             }
17         }
18         //输入不正确,超过三次
19         if (s != 0) {
20             console.log(`密码或账户有误,你还有${s}次机会,请重新输入!`);
21             s--;
22 
23         } else {
24             console.log('对不起,账户锁定!');
25             break;
26         }
27     }
28 }
29 //存款
30 let fn1 = function (i) {
31 
32     console.log('存款');
33     console.log('请输入存款金额:');
34     let cunkuan = readline.question() - 0;
35     arr[i][2]+= cunkuan;
36     console.log('系统正在为你存钱请稍等。。。。。\n存钱成功您当前余额为' + arr[i][2]);
37 }
38 //取款
39 let fn2 = function (i) {
40     console.log('取款');
41     console.log('请输入取款金额:');
42     let qukuan = readline.question() - 0;
43     if (qukuan > arr[i][2]) {
44         console.log('对不起你的余额不足!,请重新输入金额或者退出');
45     } else {
46         arr[i][2] = arr[i][2] - qukuan;
47         console.log('正在为你取钱。。。。。\n您当前余额为:' + arr[i][2]);
48     }
49 }
50 //查看
51 let fn3 = function (i) {
52     console.log('查看');
53     console.log('正在查询。。。。\n您当前的余额为:' + arr[i][2]);
54 }
55 
56 //退出
57 
58 let fn4 = function () {
59     console.log('退出');
60     console.log('欢迎你下次使用!');
61 }
62 
63 //流程
64 let mean = function (i) {
65     for (let yewu = 1; yewu >= 1; yewu++) {
66         console.log('请选择业务:\n1.存款: \n2.取款: \n3.查看: \n4.退出:');
67         let yewu = readline.question() - 0;
68         switch (yewu) {
69             case 1:
70                 fn1(i);
71                 continue;
72             case 2:
73                 fn2(i);
74                 continue;
75             case 3:
76                 fn3(i);
77                 continue;
78             case 4:
79                 fn4();
80                 return;
81         }break;
82     }
83 }
84 add();
复制代码

相关教程