发表于: 2017-02-19 00:00:53
3 1225
今天完成的事情:基本把任务一完成了(但是个人觉得代码写的很low)。把随机三个颜色用for循环写出来了。
关键代码:var color = new Array(3);
for(var i = 0 ; i < color.length; i++){
color[i]="rgb("+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+")";
console.log(color[i]);
} //使用for循环使数组获取三个随机的颜色
明天计划的事情:开始写任务2。
遇到的困难:随机三个数出来,我用了一个跟随机颜色一样的方法。关键代码:
var num = new Array(3);
for(var i = 0 ;i < 3; i++ ){
num[i]=Math.floor(Math.random()*9);
console.log(num[i]);
}
但是如何把随机三个数跟颜色关联起来不得要领。按照原来写的太低级,例如:arr[num1].style.background = color[0];显得太死板不够灵活。还是对for循环不够理解。
收获:数组跟for循环一起运用有了一点心得,但是还是不得要领。还要多多实践。
PS:https://github.com/lbw880322/updatetask1.git 这是git地址,代码链接处还是显示代码链接有误。不知道是不是我哪里弄得不对。
评论