全国统一服务热线:400-633-9193

使用javascript函数编写简单银行取钱存钱流程

    网络     2018-08-07    2579

具体代码如下所述:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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函数编写简单银行取钱存钱流程,希望对大家有所帮助


  分享到:  
0.2601s