简易ATM,- 里面现存有 100 块钱。 - 如果存钱,就用输入钱数加上先存的钱数, 之后弹出显示余额提示框 - 如果取钱,就减去取的钱数,之后弹出显示余额提示框




```javascript

  <script>
        var money = 100;
        do {
            var operation = prompt("请输入您要的操作\n 1.存钱 \n 2.取钱 \n 3.显示余额 \n 4.退出");
            if (operation === '1') {
                var m = prompt("请输入你要存的钱数")
                money += parseInt(m)
                alert('你的余额为:' + money)
            } else if (operation === '2') {
                var m = prompt("请输入你要取的钱数")
                money -= parseInt(m)
                alert('你的余额为:' + money)
            } else if (operation === '3') {
                alert('你的余额为:' + money)
            } else if (operation === '4') {
                var flag = confirm('你确定要退出吗')
                if (!flag) {
                    operation = null
                }
            } else {
                alert('请输入正确的操作数字')
            }
        } while (operation !== '4')
    </script>


![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/724161231436158.png "=600 #left")

题主不是做好了,不过要判断下取的钱数和余额,要不能余额会出现负值。。还有输入可以做一些优化,防止出现NaN

<script>
        var money = 100;
        do {
            var operation = prompt("请输入您要的操作\n 1.存钱 \n 2.取钱 \n 3.显示余额 \n 4.退出");
            if (operation === '1') {
                var m = prompt("请输入你要存的钱数")
                money += parseInt(m) || 0;//容错,防止输入非数字后parseInt为NaN,这样后续的操作不管输入说明数字都是NaN
                alert('你的余额为:' + money)
            } else if (operation === '2') {
                var m = prompt("请输入你要取的钱数")
                m = parseInt(m) || 0;//容错,防止输入非数字后parseInt为NaN,这样后续的操作不管输入说明数字都是NaN
                if (m > money) { alert('取的钱数不能大于您的余额~'); }
                else {
                    money -= m;
                    alert('你的余额为:' + money)
                }
            } else if (operation === '3') {
                alert('你的余额为:' + money)
            } else if (operation === '4') {
                var flag = confirm('你确定要退出吗')
                if (!flag) {
                    operation = null
                }
            } else {
                alert('请输入正确的操作数字')
            }
        } while (operation !== '4')
</script>