A Pen by Danny

Thumbnail
This awesome code was written by dannykorf, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright dannykorf ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Danny</title>
  
  
  
  
  
</head>

<body>

  <script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
 
<div class="discount-period">
        Deze actie loopt t/m
        <span class="active">
            31 januari
        </span>
    </div>
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/dannykorf/a-pen-by-danny-boKgEq */
  var oneDay = 24*60*60*1000;
  var currentDate = new Date();
  
  console.log(currentDate); 

  var months = ["januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"];
  
  var discountPeriod =  $(".discount-period");  
  var expirationDate = discountPeriod.find("span").text().trim().split(" ");
  var dateDays = expirationDate[0];
  var dateMonth = expirationDate[1];
  var discountDate = new Date(currentDate.getFullYear() + '-' + (months.indexOf(dateMonth)+1) + '-' + dateDays);
  
  var diffDays = Math.round(Math.abs((currentDate.getTime() - discountDate.getTime())/(oneDay)));

  if(diffDays > 7){ ///  3 or 5 or 7 for this ab test
  	discountPeriod.hide();
  }

Comments