码迷,mamicode.com
首页 > Web开发 > 详细

用JS写的取存款功能

时间:2018-05-19 13:55:28      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:nbsp   查询   lse   lin   OLE   amp   余额   用户   let   

console.log("请输入用户名:");
let username = readline.question();   // 接收用户输入的用户名
console.log("请输入密码:");
let password = readline.question();      // 接收用户输入的密码


let arr = [["123", "123"], ["456", "456"], ["789", "789"]];   // 注册后的数据库
let a = false;  // 状态值,登录的状态
let dlsb = true;  // 登陆失败  时循环
let bj = 10000;  //定义一个本金有10000元

// 登录
for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
        if (arr[i][0] === username && arr[i][1] === password) {     // 判断用户名和密码是否一致
            // console.log("登录成功");
            a = true;
            // 功能
            let tccx = true; // 定义一个状态值来 退出循环
            while (tccx) {
                // 功能提示
                let qk = "1.取款", ck = "2.存款", cx = "3.查询剩余金额", tc = "4.退出";
                console.log(qk, ck, cx, tc);
                let cz = readline.question();
                switch (cz) {
                    case "1": {
console.log("请输入取款金额:");
                        let qkje = readline.question() - 0;
                        console.log(`确定取款:${qkje}元? `);
                        console.log("确定取款请输入 1, 取消取款请输入 2。");
                        let qdqk = readline.question();
                        if (qkje > bj) {
                            console.log("抱歉,你余额不足无法进行取款。");
                        } else {
                            switch (qdqk) {
                                case "1": {
                                    bj -= qkje;
                                    console.log("你已经成功取款" + qkje + "元,剩余" + bj + "元。");
                                    break;
                                }
                                case "2": {
                                    console.log("你取消了此操作。");
                                    break;
                                }
                            }
                        }
                        break;
                    }

                    case "2": {
                        console.log("请输入存款金额:");
                        let qkje = readline.question() - 0;
                        console.log(`确定存款:${qkje}元? `);
                        console.log("确定存款请输入 1, 取消存款请输入 2。");
                        let qdqk = readline.question();
                        switch (qdqk) {
                            case "1": {
                                bj += qkje;
                                console.log("你已经成功存款" + qkje + "元,剩余" + bj + "元。");
                                break;
                            }
                            case "2": {
                                console.log("你取消了这次操作。");
                                break;
                            }
                        }
                        break;
                    }
                    case "3":
                        console.log("你的剩余金额为:" + bj + "元");
                        break;
                    case "4": {
                        console.log("感谢你的使用,欢迎你下次使用");
                        tccx = false;
                        break;
                    }
                    default:
                        console.log("核对后再输入相应内容");
                }
            }
            break;
        }
        break;
    }
    break;
}
if (a == false) {
    let jx = true;  // 状态值,用于下面的while循环

    console.log("用户名或者密码不正确,请核对后输入。如果你再输入错误 2 次会自动冻结账户。是否继续输入?继续请输入 1 ,退出请输入 2。");
    let sfjx = readline.question();  // 让用户决定是否继续
    let srcs = 1; // 输入次数
    switch (sfjx) {
        case "1": {
            while (srcs) {
                console.log("请输入用户名");
                username = readline.question();
                console.log("请输入密码");
                password = readline.question();
                srcs++;

                for (let i = 0; i < arr.length; i++) {
                    for (let j = 0; j < arr[i].length; j++) {
                        if (arr[i][0] === username && arr[i][1] === password) {     // 判断用户名和密码是否一致
                            // console.log("登录成功");
                            srcs = 0;

                            // 功能
                            let tccx = true; // 定义一个状态值来 退出循环
                            while (tccx) {
                                // 功能提示
                                let qk = "1.取款", ck = "2.存款", cx = "3.查询剩余金额", tc = "4.退出";
                                console.log(qk, ck, cx, tc);
                                let cz = readline.question();
                                switch (cz) {
                                    case "1": {
                                        console.log("请输入取款金额:");
                                        let qkje = readline.question() - 0;
                                        console.log(`确定取款:${qkje}元? `);
                                        console.log("确定取款请输入 1, 取消取款请输入 2。");
                                        let qdqk = readline.question();
                                        if (qkje > bj) {
                                            console.log("抱歉,你余额不足无法进行取款。");
                                        } else {
                                            switch (qdqk) {
                                                case "1": {
                                                    bj -= qkje;
                                                    console.log("你已经成功取款" + qkje + "元,剩余" + bj + "元。");
                                                    break;
                                                }
                                                case "2": {
                                                    console.log("你取消了此操作。");
                                                    break;
                                                }
                                            }
                                        }
                                        break;
                                    }

                                    case "2": {
                                        console.log("请输入存款金额:");
                                        let qkje = readline.question() - 0;
                                        console.log(`确定存款:${qkje}元? `);
                                        console.log("确定存款请输入 1, 取消存款请输入 2。");
                                        let qdqk = readline.question();
                                        switch (qdqk) {
                                            case "1": {
                                                bj += qkje;
                                                console.log("你已经成功存款" + qkje + "元,剩余" + bj + "元。");
                                                break;
                                            }
                                            case "2": {
                                                console.log("你取消了这次操作。");
                                                break;
                                            }
                                        }
                                        break;
                                    }
                                    case "3":
                                        console.log("你的剩余金额为:" + bj + "元");
                                        break;
                                    case "4": {
                                        console.log("感谢你的使用,欢迎你下次使用");
                                        tccx = false;
                                        break;
                                    }
                                    default:
                                        console.log("核对后再输入相应内容");
                                }
                            }
                            break;
                        }
                        break;
                    }
                    break;
                }
                if (srcs == 3) {
                    console.log("你输入的用户名或密码错误超过3次,自动冻结该账户。");
                    break;
                }
            }
        }
        case "2": {
            jx = false;
            break;
        }
    }
}

用JS写的取存款功能

标签:nbsp   查询   lse   lin   OLE   amp   余额   用户   let   

原文地址:https://www.cnblogs.com/yehongrun/p/9060062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!