Use js to realize simple ATM machine deposit and withdrawal function-pink teacher dark horse front end

@[TOC]Title:

  1. There are 100 yuan in it.
    2. If you deposit money, just enter the amount of money plus the amount you deposited first, and then a balance prompt box will pop up
    3. If you withdraw money, subtract the amount of money you withd, and then a balance prompt box will pop up
    4. If you display the balance , The balance will be output.
    5. If you exit, the exit information prompt box will pop up.
    Source: Dark Horse Front End Course
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var balance = 100;
        while (true) {
    
    
            var way = prompt('请输入您要的操作:\n1.存钱\n2.取钱\n3.显示余额\n4.退出')
            switch (way) {
    
    
                case '1': var str1 = prompt('请输入你要存入的金额:');
                    balance += parseFloat(str1);
                    alert('您的余额是:' + balance);
                    // return balance;
                    break;
                case '2': var str2 = prompt('请输入你要取出的金额:');
                    balance = balance - parseFloat(str2);
                    alert('您的余额是:' + balance);
                    break;

                case '3': alert('您的余额是:' + balance);
                    break;
                case '4':
                    alert('感谢您的使用');
                    break;
                default:
                    alert('您输入的不正确 请输入1~4之间的数');
            }
            if (way == 4) {
    
    
                break;
            }
        }


    </script>
</head>

<body>

</body>

</html>

Guess you like

Origin blog.csdn.net/weixin_44365885/article/details/112974432