我的代码为什么不能输出呢?

来源:4-10 编程练习

慕粉1440489053

2017-02-28 00:02

var infor=[["小A","女",21,"大一"],["小B","男",23,"大三"],["小C","男",24,"大四"],["小D","女",21,"大一"],["小E","女",22,"大四"],["小F","男",21,"大一"],["小G","女",22,"大二"],["小H","女",20,"大三"],["小I","女",20,"大一"],["小J","男",20,"大三"]];

        switch(infor[i][3]==="大一"&&infor[i][1]==="女"){

      case true:

             document.write("大一女生信息:"+infor[i]);

       break;

}


写回答 关注

2回答

  • 慕粉1844174621
    2017-03-03 14:52:39
    /*我也是最进才学的,这是我的方法你看行不行.
    ①你应该是像楼上说的没加for或其他循环语句;②且条件要一个个放,不然循环输出会出错,就不显示了;③下面是我多次修改的代码,让我们共同进步!:
    */
    
    var infor=[
    ["小A","女",21,"大一"],["小B","男",23,"大三"],
    ["小C","男",24,"大四"],["小D","女",21,"大一"],
    ["小E","女",22,"大四"],["小F","男",21,"大一"],
    ["小G","女",22,"大二"],["小H","女",20,"大三"],
    ["小I","女",20,"大一"],["小J","男",20,"大三"]
    ];
    
    document.write("<b>大一女生:</b><br/>");
    for(var i=0;i<10;i++){
    switch(infor[i][3]){
          case "大一":
                 document.write("大一女生信息:"+infor[i]+"<br/>");
           break;
    
       }
    }
    
    document.write("<br/><b>女生姓名:</b><br/>");
    for(var i=0;i<10;i++){
    
    switch(infor[i][1]){
          case "女":
                 document.write("大一女生信息:"+infor[i][0]+"<br/>");
           break;
       }
    }


    EricZo...

    第二轮女生循环你并没有将上一循环得出的数据统计并再次筛选,所以你第二轮循环只是筛选的所有女生,而不是大一女生

    2017-03-06 16:14:59

    共 1 条回复 >

  • 慕粉1440489053
    2017-02-28 00:04:58

    找到原因了 没有写FOR循环

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468060 学习 · 21891 问题

查看课程

相似问题