其他分享
首页 > 其他分享> > for循环结构案列实现之打印九九乘法表和简易ATM

for循环结构案列实现之打印九九乘法表和简易ATM

作者:互联网

九九乘法表 

  var str = '';
        for(var i=1;i<=9;i++){
            for(var j=1;j<=i;j++){
                // str = str + '';
               str +=j+'×'+i+'='+ j*i+ '\t';
            }
            str = str +'\n';
        }
        console.log(str);

 简易ATM实现

 

  var money = 100;
   while(true){
   var cunqian = "1.存钱";
    var quqian = "2.取钱";
    var yue = "3.余额";
    var exit = "4.退出";
    var caidan = prompt("请输入你要执行的操作:\n"+cunqian+"\n" + ""+quqian+"\n" + ""+yue+"\n" +"" + exit +"\n");
        if(caidan == 1){
            var add = parseFloat(prompt("请输入存钱的钱数:"));
            money += add;
        alert("你现在的钱数为:"+money+"元");
        continue;
        }else if(caidan == 2){
            var sub =parseFloat(prompt("请输入你取钱的数:"));
            money -=sub;
            alert("你现在的钱数为:"+money+"元");
            continue;
        }else if(caidan == 3){
            alert("你现在的钱数为:"+money+"元");
            continue;
        }else if(caidan == 4){
            alert("正在退出");
            break;
        }else{
            alert('没有该选项,请重新输入');
            continue;
        }   

    }

标签:九九乘法,caidan,money,ATM,案列,alert,continue,var,else
来源: https://blog.csdn.net/weixin_58139900/article/details/120918193