Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Thanks to @Mottie, @vindicateme and @TheDoc:)

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #154084
    bcintegrity1
    Participant

    Thanks for your help with my bugs. Here’s the test page. Everything works as expected! I managed to get the review averages, round them…, and use them to create an accurate star rating as well.

    Have an AWESOME weekend!

    Here’s the finished code:^)

    $('.lbox').each(function(event) {
    
     var name = $(this).find("p").text();
     name = name.split(/^(\w+)\s+(\w+)/);
     var firstName = name[1];
     var lastName = name[2];
     var folder = "reviews-pest-control-va";
     var reviewsPath = folder + '/' + lastName + ',' + firstName + '.php';
     var reviewsFile = reviewsPath.toLowerCase();
     var rating = $(this).find('.rating');
    
     $.get(reviewsFile, function(data){
    
      var $reviewTotal = $(data).find(".review").length;
      var $star5 = ($(data).find(".five").length) * (5);
      var $star4 = ($(data).find(".four").length) * (4);
      var $star3 = ($(data).find(".three").length) * (3);
      var $star2 = ($(data).find(".two").length) * (2);
      var $star1 = ($(data).find(".one").length) * (1);
      var $star0 = ($(data).find(".zero").length) * (0);
    
      var $reviewAvg = ($star5 + $star4 + $star3 + $star2 + $star1 + $star0) / ($reviewTotal);
      var $avgReview = rating.append("AVERAGE RATING: " + $reviewAvg.toFixed(1));
    
      var middle = $(rating).parent().find(".middleimage");
      var $forPix = ($reviewAvg) * (12.8);
      var $pixWidth = $forPix.toFixed(0);
      middle.css({"width": $pixWidth});
    
     });
    });
    
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.