使用流程控制语句写 ATM let username = "z", password = "1", account = 10000, isLogin = false; while (!isLogin) { let usernameInput = window.prompt("请输入用户名:"); let passwordInput = window.prompt("请输入密码:"); console.log(usernameInput, passwordInput) if (usernameInput === username && password === passwordInput) { let flag = true; while (flag) { let option = ~~window.prompt("选择操作类型: 1. 查询 2. 存款 3. 取款 4. 修改密码 5. 退出 6. 退出登录"); switch (option) { case 1: console.log("你的余额为: " + account); break; case 2: { let money = ~~window.prompt("输入存款金额: "); account += money; } break; case 3: { let money = ~~window.prompt("输入取款金额: "); account -= money; } break; case 4: password = window.prompt("输入新密码: "); break; case 5: flag = false; console.log("退出"); break; case 6: flag = false; isLogin = true; } } }}
时间: 2024-10-12 20:55:23