April123_
2015-02-20 16:50
为什么顺序是0 7 2 4????完全不理解
题目给的数值是
var arr = ['*','##',"***","&&","****","##*"];
arr[7] = "**";
而array里面拆开得到的数值是
arr[0] = *
arr[1] = ##
arr[2] = ***
arr[3] = &&
arr[4] = ****
arr[5] = ##*
所以你得到0724
但我觉得这样写会比较符合题目要求
<!DOCTYPE HTML> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>数组</title> <script type="text/javascript"> //创建数组 var arr = ['*','##',"***","&&","****","##*"]; //显示数组长度 var length = arr.length; arr[7] = "**"; //将数组内容输出,完成达到的效果。 var row = 4; var row_count = 0; for(var i=0; i<length; i++){ row_count++; if(row_count<=row){ if(arr[i].length == i+1){ if(arr[i].indexOf('*') === -1) document.write(arr[7]+"<br>"); else if(arr[i].length == (i+1)){ document.write(arr[i]+"<br>"); } } else{ for(var j=0; j<i+1; j++){ document.write("*"); } document.write("<br>"); } } } </script> </head> <body> </body> </html>
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题