In the site that I designed with WordPress, I have to create the number of visitors and their rating as stars in the products section. I used these javascript codes, but not work.Thank you in advance for your cooperation
var starRating = [...document.querySelectorAll('.starRating')].map(o => o.innerText).join('\n');
for (let x = 0; x < starRating.length; x++){
function Getrating() {
$starNumber = "5";
for($x=1;$x<=$starNumber;$x++) {
$output .= '<i class="fa fa-star" aria-hidden="true"></i>';
}
if (strpos($starNumber,'.')) {
$output .= '<i class="fa fa-star-half-o" aria-hidden="true"> </i>';
$x++;
}
while ($x<=5) {
$output .= '<i class="fa fa-star-o" aria-hidden="true"></i>';
$x++;
}
return $output;
}
add_shortcode('starrating', 'Getrating');
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
//wordpress code
<div class="starRating">
<?php the_field('rating'); ?> /
<?php the_field('review_count'); ?>
</div>
//html code in inspector
<div class="starRating"> 3.2 /345 </div>
<div class="starRating"> 4 /4567 </div>
<div class="starRating"> 4.7 /987 </div>
<div class="starRating"> 2.7 /1210 </div>