为了账号安全,请及时绑定邮箱和手机立即绑定

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

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 回答

/*我也是最进才学的,这是我的方法你看行不行.
①你应该是像楼上说的没加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;
   }
}


0 回复 有任何疑惑可以回复我~
#1

EricZoo

第二轮女生循环你并没有将上一循环得出的数据统计并再次筛选,所以你第二轮循环只是筛选的所有女生,而不是大一女生
2017-03-06 回复 有任何疑惑可以回复我~

找到原因了 没有写FOR循环

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信