0

This script is a countdown for Christmas

Is it possible to display in an AMP HTML web page or not? If possible, how to do it? What is the minify Javascript that I should add to the AMP web page, please help me.

<script type="text/javascript">// <![CDATA[
var today=new Date()

//Enter the occasion's MONTH (1-12) and DAY (1-31):
var theoccasion=new Date(today.getFullYear(), 12, 25)

//Customize text to show before and on occasion. Follow grammer below:
var beforeOccasionText="left until Christmas :) "
var onOccasiontext="Today is Christmas. Happy Holidays!"

var monthtext=new 
Array("Jan","Feb","Mar","April","May","June","July","Aug","Sep","Oct","Nov","Dec")
theoccasion.setMonth(theoccasion.getMonth()-1) //change to 0-11 month format
var showdate="("+monthtext[theoccasion.getMonth()]+" "+theoccasion.getDate()+")" //show date of occasion

var one_day=1000*60*60*24
var calculatediff=""

calculatediff=Math.ceil((theoccasion.getTime()-today.getTime())/(one_day))
if (calculatediff<0){ //if bday already passed
var nextyeartoday=new Date()
nextyeartoday.setFullYear(today.getFullYear()+1)
calculatediff=Math.ceil((nextyeartoday.getTime()-
today.getTime())/(one_day)+calculatediff)
}

//Display message accordingly
var pluraldayornot=(calculatediff==1)? "day" : "days"
if (calculatediff>0)
    document.write("<b>"+calculatediff+" "+pluraldayornot+" "+beforeOccasionText+" "+showdate+"!</b>")
else if (calculatediff==0)
document.write("<b>"+onOccasiontext+" "+showdate+"!</b>")
// ]]></script>
M.K.Dan
  • 39
  • 9

2 Answers2

0

JavaScript are forbidden in AMP Sites

Lovntola
  • 1,409
  • 10
  • 31
0

You can't use custom javascript in AMP html. Instead, you should use one of AMP custom components to imitate whatever your script is supposed to do. If you tell me what you're trying to do with that script, I might be able to point you in the right direction.

Edit: you might be able to achieve what you're trying to do by using an HTML templating language that can do some math for you.

Ksenia
  • 536
  • 5
  • 14