I have an array slides that contains variable stars inside of it. I need to grab the value for stars on each slide, then use that number to repeat an HTML string for each slide.
I can get the value of stars, but it iterates through all 6 slides, and provides their values 6 times.
I need to get all the values of stars only 1 time.
var slides = [
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 4
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 3
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 2
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 1
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 5
},
{
'text' : 'The staff was fantastic and very friendly. I would definitely recommend them to anyone. The care has been great!! - ONLINE REVIEWER',
'stars' : 2
}
];
$scope.addStars = function(){
i = 1;
for (i=1; i<slides.length; i++) {
var starsCount = slides[i].stars;
var starsHTML = '<a href="#">☆</a>';
starsFinal = starsHTML.repeat(starsCount);
console.log(starsFinal);
}
}
addStars(). As this logic is, it shouldn't do what you are saying it is, provided it is called only once.