Reputation: 33
I have a problem as such:
i = [
'pic1.gif',
'pic2.gif'
];
I generate a random sequence of n pictures from the two pictures as such:
a = function(n){
str = '<div>'
for(i = 0; i < n; i++){
str += '<img src="'+ /*randomElement of array i*/ +'">';
}
str += '<div>';
return str;
}
What I need to do now is how to count the number of pic1 generated?
Upvotes: 0
Views: 70
Reputation: 595
if you know the name of the pic, and if does not change, we can find the count using simple variable
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;
}
Upvotes: 1