我有一个问题:
i = [
'pic1.gif',
'pic2.gif'
];
我从两张图片中生成一个随机的 n 张图片序列,如下所示:
a = function(n){
str = '<div>'
for(i = 0; i < n; i++){
str += '<img src="'+ /*randomElement of array i*/ +'">';
}
str += '<div>';
return str;
}
我现在需要做的是如何统计生成的pic1的数量?
如果你知道图片的名字,如果没有改变,我们可以使用简单的变量找到计数
a = function(n){
str = '<div>'
**//adding a temp variable**
count_img =0;
for(i = 0; i < n; i++){
str += '<img src="'+ /*randomElement of array i*/ +'">';
**//check the image name
if(imagename matches){
//increment the count
count_img = count_img +1;
}**
}
**console.log(count_img);**
str += '<div>';
return str;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句