{"id":25166,"date":"2015-11-30T21:01:52","date_gmt":"2015-11-30T13:01:52","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=25166"},"modified":"2024-06-20T19:17:35","modified_gmt":"2024-06-20T11:17:35","slug":"advent-calendar-javascript","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/","title":{"rendered":"Create Your Own Advent Calendar with JavaScript"},"content":{"rendered":"<p>Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an Advent Calendar or an Advent Wreath. While Advent doesn\u2019t have a set start date, Advent Calendars typically kick off on December 1.<\/p>\n<p>Advent Calendars vary widely depending on local traditions but often feature a <strong>large rectangular card with 24 windows or doors<\/strong>. These doors open to reveal daily messages, poems, prayers, or small gifts as you count down from December 1 to 24.<\/p>\n<p>In this tutorial, you\u2019ll learn how to craft your own Advent Calendar using <strong>object-oriented JavaScript<\/strong>. This project uses plain JavaScript, making it simple to integrate into your website.<\/p>\n<p><a href=\"https:\/\/hongkiat.github.io\/advent-calendar\/\" class=\"su-button su-button-style-flat\" style=\"color:#FFFFFF;background-color:#2D89EF;border-color:#246ec0;border-radius:0px\" target=\"__blank\" rel=\"noopener nofollow\"><span style=\"color:#FFFFFF;padding:7px 20px;font-size:16px;line-height:24px;border-color:#6cadf4;border-radius:0px;text-shadow:none\"><i class=\"sui sui-external-link\" style=\"font-size:16px;color:#fff\"><\/i> View demo<\/span><\/a>\n<a href=\"https:\/\/github.com\/hongkiat\/advent-calendar\/\" class=\"su-button su-button-style-flat\" style=\"color:#FFFFFF;background-color:#2D89EF;border-color:#246ec0;border-radius:0px\" target=\"__blank\" rel=\"noopener nofollow\"><span style=\"color:#FFFFFF;padding:7px 20px;font-size:16px;line-height:24px;border-color:#6cadf4;border-radius:0px;text-shadow:none\"><i class=\"sui sui-external-link\" style=\"font-size:16px;color:#fff\"><\/i> Download source<\/span><\/a><\/p>\n<h2>Designing Your JavaScript Advent Calendar<\/h2>\n<p>Our digital Advent Calendar features 24 interactive doors set against a festive background. Each door, when clicked, reveals a Christmas-themed quote in an alert message. True to tradition, doors can only be opened on their respective dates, mimicking the suspense of a physical Advent Calendar. Active doors are distinguished with a white border and background, while inactive ones are light green. We leverage HTML5, CSS3, and JavaScript to craft this engaging holiday countdown.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg\" alt=\"Advent Calendar Screenshot\" width=\"399\" height=\"532\"><\/figure>\n<h2>Step 1: Setting Up File Structure and Resources<\/h2>\n<p>To begin, select a fitting background image. For my project, I opted for a portrait-oriented image from <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/pixabay.com\">Pixabay<\/a>, arranging the calendar in <strong>4 columns and 6 rows<\/strong>. You can choose a landscape orientation if preferred \u2013 simply adjust the door positions in the JavaScript code to <strong>6 columns and 4 rows<\/strong>.<\/p>\n<p>Once you have your image, create a folder named <strong>\/images<\/strong> in your project directory and save the image there. This will be our sole image resource for the project.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-background.jpg\" alt=\"Advent Calendar Background\" width=\"400\" height=\"533\"><\/figure>\n<p>Next, prepare the JavaScript files by creating a <strong>\/scripts<\/strong> folder in the root directory. Add two empty files named <strong>calendar.js<\/strong> and <strong>messages.js<\/strong>. <strong>Calendar.js<\/strong> will manage the calendar\u2019s functionality, while <strong>messages.js<\/strong> will store the pop-up messages for each day.<\/p>\n<p>Additionally, create two empty files named <strong>index.html<\/strong> and <strong>style.css<\/strong> in the root directory for your HTML and CSS code, respectively.<\/p>\n<p>With these resources and file structure in place, you\u2019re all set to start building your Advent Calendar. Here\u2019s what your root folder should look like:<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/file-structure.jpg\" alt=\"Advent Calendar File Structure\" width=\"700\" height=\"218\"><\/figure>\n<h2>Step 2: Assembling the HTML Structure<\/h2>\n<p>The HTML structure for our Advent Calendar is straightforward. The CSS stylesheet is linked within the <strong>&lt;head&gt;<\/strong> section, while the <strong>two JavaScript files are placed at the bottom of the &lt;body&gt; section<\/strong> to ensure they load after the HTML elements they manipulate. This setup prevents execution errors that occur if scripts are loaded before the HTML elements they reference.<\/p>\n<p>The core of the Advent Calendar is contained within an <strong>&lt;article&gt;<\/strong> <a href=\"https:\/\/www.hongkiat.com\/blog\/html-5-semantics\/\">semantic tag<\/a>. The festive background image is embedded directly using an <strong>&lt;img&gt;<\/strong> tag rather than as a CSS background to facilitate easier DOM manipulation.<\/p>\n<p>Below the image, an empty unordered list with the ID <strong>\u201cadventDoors\u201d<\/strong> is prepared. This list will be dynamically filled by the JavaScript. For users without JavaScript enabled, they will see only the static Christmas image, ensuring basic functionality remains intact.<\/p>\n<pre>\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"utf-8\"&gt;\r\n    &lt;title&gt;Advent Calendar&lt;\/title&gt;\r\n    \r\n    &lt;!-- Mobile-friendly viewport --&gt;\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\r\n    \r\n    &lt;!-- Style sheet link --&gt;\r\n    &lt;link href=\"style.css\" rel=\"stylesheet\" media=\"all\"&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n\r\n    &lt;article&gt;\r\n        &lt;h1&gt;Advent Calendar&lt;\/h1&gt;\r\n        \r\n        &lt;img src=\"advent-calendar-javascript\/background.jpg\" alt=\"Advent Calendar\" id=\"adventCal\"&gt;\r\n        \r\n        &lt;ul id=\"adventDoors\"&gt;&lt;\/ul&gt;\r\n    &lt;\/article&gt;\r\n    \r\n    &lt;!-- Scripts at the end to ensure HTML elements load first --&gt;\r\n    &lt;script src=\"scripts\/messages.js\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"scripts\/calendar.js\"&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h2>Step 3: Filling the \u201cMessages\u201d Array with Quotes<\/h2>\n<p>To bring our Advent Calendar to life, we need 24 festive quotes. I\u2019ve selected my favorites from <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.goodreads.com\/quotes\">GoodReads<\/a>. You can choose your own source for quotes that resonate with the holiday spirit.<\/p>\n<p>In the <strong>scripts\/messages.js<\/strong> file, we will separate these quotes from the main functionality. Each quote is stored within a nested array structure in the <strong>messages<\/strong> array, with each element consisting of a quote and its author. Populate your array using the following structure:<\/p>\n<pre>\r\nvar messages = [\r\n    [\"Quote 1\", \"Author 1\"],\r\n    [\"Quote 2\", \"Author 2\"],\r\n    ...\r\n    [\"Quote 24\", \"Author 24\"]\r\n];\r\n<\/pre>\n<h2>Step 4: Crafting Basic CSS Styles for the Doors<\/h2>\n<p>Before scripting the door functionality, we need to establish the visual design using CSS. Envisioning the final layout, we will organize the doors into 4 columns and 6 rows. To achieve this, we use <strong>position: relative<\/strong> for the container and <strong>position: absolute<\/strong> for each door, allowing precise control over their placement through additional CSS properties specified in the JavaScript.<\/p>\n<p>It\u2019s also crucial to distinguish between active and inactive doors. The <strong>.disabled<\/strong> class will be applied dynamically by JavaScript to inactive doors. Below, you\u2019ll find the CSS needed for the enabled state (white border and text with a translucent white background on hover) and the disabled state (light green text and border with a translucent light green background). Feel free to adjust the colors and styles to match your design preferences.<\/p>\n<pre>\r\nul#adventDoors {\r\n    position: relative;\r\n    list-style: none;\r\n    padding: 0;\r\n    margin: 0;\r\n}\r\n#adventDoors li {\r\n    position: absolute;\r\n}\r\n#adventDoors li a {\r\n    color: #fff;\r\n    width: 100%;\r\n    height: 100%;\r\n    font-size: 24px;\r\n    text-align: center;\r\n    display: flex;\r\n    flex-direction: column;\r\n    justify-content: center;\r\n    text-decoration: none;\r\n    border: 1px solid #fff;\r\n}\r\n#adventDoors li a:not(.disabled):hover {\r\n    background-color: rgba(255, 255, 255, 0.15);\r\n}\r\n#adventDoors li a.disabled {\r\n    border-color: #b6fe98;\r\n    background-color: rgba(196, 254, 171, 0.15);\r\n    color: #b6fe98;\r\n    cursor: default;\r\n}\r\n<\/pre>\n<h2>Step 5: Initializing Global Variables<\/h2>\n<p>From this point, our focus shifts exclusively to the <strong>scripts\/calendar.js<\/strong> file. We need to define two global variables essential for our Advent Calendar\u2019s functionality.<\/p>\n<p>The <strong>myCal<\/strong> variable represents the calendar image, now a JavaScript object. This image was embedded in the <strong>index.html<\/strong> file back in Step 2. We\u2019ll be positioning doors over this image in Step 7. We identify the image in our script using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/getElementById\">getElementById()<\/a> method, making <strong>myCal<\/strong> an <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/API\/HTMLImageElement\">HTMLImageElement<\/a> DOM object.<\/p>\n<p>The <strong>currentDate<\/strong> variable captures today\u2019s date, which helps our script determine which doors should be active or inactive. This is achieved by creating a new instance of the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Date\">Date<\/a> class.<\/p>\n<p>Insert this code at the beginning of your <strong>calendar.js<\/strong> file:<\/p>\n<pre>\r\nvar myCal = document.getElementById(\"adventCal\");\r\nvar currentDate = new Date();\r\n<\/pre>\n<h2>Step 6: Defining the \u201cDoor\u201d Class<\/h2>\n<p>Our calendar will feature 24 doors, each represented by an instance of a \u201cDoor\u201d class. This class takes two parameters: <strong>calendar<\/strong>, the background image, and <strong>day<\/strong>, the specific day in December it represents.<\/p>\n<p>The values for these parameters will be assigned during the final instantiation phase in Step 8. Here, we outline the five properties and one method that constitute the Door class. The method <strong>content()<\/strong> will be discussed in the next step.<\/p>\n<h3>Properties: \u201cwidth\u201d & \u201cheight\u201d<\/h3>\n<p>The <strong>width<\/strong> and <strong>height<\/strong> properties dynamically adjust to the size of the background image. We use multipliers to leave space for margins between doors and along the edges of the calendar.<\/p>\n<h3>Property: \u201cadventMessage\u201d<\/h3>\n<p>This property stores the quote and author for each door, retrieved from the <strong>messages[]<\/strong> array based on the current date. For example, on December 1st, <strong>messages[0]<\/strong> is accessed since arrays in JavaScript are zero-indexed.<\/p>\n<h3>Properties: \u201cx\u201d & \u201cy\u201d<\/h3>\n<p>The <strong>x<\/strong> and <strong>y<\/strong> properties determine the precise position of each door, aiding in setting the CSS <strong>top<\/strong> and <strong>left<\/strong> properties. These calculations use margins and multipliers to ensure proper placement within the grid structure defined in Step 4.<\/p>\n<pre>\r\nfunction Door(calendar, day) {\r\n    this.width = calendar.width * 0.95 \/ 4 - (calendar.width * 0.1);\r\n    this.height = calendar.height * 0.95 \/ 6 - (calendar.height * 0.1);\r\n    this.adventMessage = 'Day ' + day + ': \"' + messages[day - 1][0] + '\" by ' + messages[day - 1][1];\r\n    this.x = calendar.width * 0.04 * (day % 4);\r\n    this.y = Math.floor(day \/ 4) * (calendar.height * 0.11);\r\n\r\n    this.content = function() {\r\n        \/\/ Content method details to follow in the next step\r\n    };\r\n}\r\n<\/pre>\n<h2>Step 7: Implementing the \u201cContent()\u201d Method for Displaying Doors<\/h2>\n<p>The <strong>content()<\/strong> method is crucial as it dynamically displays doors within the browser. We start by creating a new DOM node, <strong>node<\/strong>, to generate the <strong>&lt;li&gt;<\/strong> elements. Each of these elements represents a door within the unordered list <strong>#adventDoors<\/strong>, previously defined in our HTML.<\/p>\n<p>Once the Door class is instantiated 24 times (as we\u2019ll do in Step 8), we will have 24 corresponding &lt;li&gt; elements. These are added to the unordered list using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Node\/appendChild\">appendChild()<\/a> method.<\/p>\n<p>Each door\u2019s unique identifier is set using the <strong>node.id<\/strong> property, formatting each as <strong>id=\u201ddoor1\u2033<\/strong>, <strong>id=\u201ddoor2\u2033<\/strong>, etc. This setup is vital for the looping mechanism in the next step.<\/p>\n<p>The door\u2019s inline style is defined via the <strong>node.style.cssText<\/strong> property, incorporating CSS rules directly within our HTML. This application uses positional attributes and dimensions defined in Step 6.<\/p>\n<p>An <strong>&lt;a&gt;<\/strong> tag is embedded within each door to make them interactive, using the <strong>innerNode<\/strong> variable. This link is appended to the corresponding list item and displays the door number using the <strong>innerHTML<\/strong> property. The <strong>href=\u201d#\u201d<\/strong> attribute ensures that the links are clickable but do not navigate away from the page.<\/p>\n<p>In the final conditional check, we determine whether a door should be enabled or disabled based on the current date and whether it\u2019s December, utilizing JavaScript\u2019s <strong>getMonth()<\/strong> method. Doors corresponding to future dates are disabled, and an appropriate CSS class is applied to indicate this state. Conversely, enabled doors will display an Advent message upon clicking.<\/p>\n<pre>\r\nthis.content = function() {\r\n    var node = document.createElement(\"li\");\r\n    document.getElementById(\"adventDoors\").appendChild(node);\r\n    node.id = \"door\" + day;\r\n    node.style.cssText = \"width: \" + this.width + \"px; height: \" + this.height +\r\n    \"px; top: \" + this.y + \"px; left: \" + this.x + \"px;\";\r\n\r\n    var innerNode = document.createElement(\"a\");\r\n    document.getElementById(node.id).appendChild(innerNode);\r\n    innerNode.innerHTML = day;\r\n    innerNode.href = \"#\";\r\n\r\n    if ((new Date().getMonth() + 1) < 12 || new Date().getDate() < day) {\r\n        innerNode.className = \"disabled\";\r\n        innerNode.onclick = function() { return false; };\r\n    } else {\r\n        var adventMessage = this.adventMessage;\r\n        innerNode.onclick = function() { alert(adventMessage); return false; };\r\n    }\r\n};\r\n<\/pre>\n<h2>Step 8: Instantiating the \"Door\" Objects<\/h2>\n<p>We initialize the Door class 24 times using an Immediately Invoked Function Expression (IIFE). This method is ideal as it executes immediately without needing to store the result in a variable.<\/p>\n<p>We create an array, <strong>doors[]<\/strong>, to hold our Door objects. Looping from 1 to 24, we instantiate each Door and invoke its content method, thereby preparing all the doors for display.<\/p>\n<pre>\r\n(function() {\r\n    var doors = [];\r\n\r\n    for (var i = 0; i < 24; i++) {\r\n        doors[i] = new Door(myCal, i + 1);\r\n        doors[i].content();\r\n    }\r\n\r\n    return doors;\r\n})();\r\n<\/pre>\n<p><!-- Updated button links -->\n<a href=\"https:\/\/hongkiat.github.io\/advent-calendar\/\" class=\"su-button su-button-style-flat\" style=\"color:#FFFFFF;background-color:#2D89EF;border-color:#246ec0;border-radius:0px\" target=\"__blank\" rel=\"noopener nofollow\"><span style=\"color:#FFFFFF;padding:7px 20px;font-size:16px;line-height:24px;border-color:#6cadf4;border-radius:0px;text-shadow:none\"><i class=\"sui sui-external-link\" style=\"font-size:16px;color:#fff\"><\/i> View demo<\/span><\/a>\n<a href=\"https:\/\/github.com\/hongkiat\/advent-calendar\/\" class=\"su-button su-button-style-flat\" style=\"color:#FFFFFF;background-color:#2D89EF;border-color:#246ec0;border-radius:0px\" target=\"__blank\" rel=\"noopener nofollow\"><span style=\"color:#FFFFFF;padding:7px 20px;font-size:16px;line-height:24px;border-color:#6cadf4;border-radius:0px;text-shadow:none\"><i class=\"sui sui-external-link\" style=\"font-size:16px;color:#fff\"><\/i> Download source<\/span><\/a> <\/p>","protected":false},"excerpt":{"rendered":"<p>Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an Advent Calendar or an Advent Wreath. While Advent doesn\u2019t have a set start date, Advent Calendars typically kick off on December 1. Advent Calendars vary widely depending on local traditions but often&hellip;<\/p>\n","protected":false},"author":146,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[2889,4117],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Create Your Own Advent Calendar with JavaScript - Hongkiat<\/title>\n<meta name=\"description\" content=\"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Your Own Advent Calendar with JavaScript\" \/>\n<meta property=\"og:description\" content=\"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-30T13:01:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-20T11:17:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg\" \/>\n<meta name=\"author\" content=\"Anna Monus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anna Monus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/\"},\"author\":{\"name\":\"Anna Monus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\"},\"headline\":\"Create Your Own Advent Calendar with JavaScript\",\"datePublished\":\"2015-11-30T13:01:52+00:00\",\"dateModified\":\"2024-06-20T11:17:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/\"},\"wordCount\":1464,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/advent-calendar-javascript\\\/calendar-screenshot.jpg\",\"keywords\":[\"Calendar Design\",\"Javascripts\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/\",\"name\":\"Create Your Own Advent Calendar with JavaScript - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/advent-calendar-javascript\\\/calendar-screenshot.jpg\",\"datePublished\":\"2015-11-30T13:01:52+00:00\",\"dateModified\":\"2024-06-20T11:17:35+00:00\",\"description\":\"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/advent-calendar-javascript\\\/calendar-screenshot.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/advent-calendar-javascript\\\/calendar-screenshot.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/advent-calendar-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Your Own Advent Calendar with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\",\"name\":\"Anna Monus\",\"description\":\"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.\",\"sameAs\":[\"https:\\\/\\\/www.annalytic.com\\\/\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/anna_monus\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Create Your Own Advent Calendar with JavaScript - Hongkiat","description":"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Create Your Own Advent Calendar with JavaScript","og_description":"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an","og_url":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2015-11-30T13:01:52+00:00","article_modified_time":"2024-06-20T11:17:35+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg","type":"","width":"","height":""}],"author":"Anna Monus","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Anna Monus","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/"},"author":{"name":"Anna Monus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e"},"headline":"Create Your Own Advent Calendar with JavaScript","datePublished":"2015-11-30T13:01:52+00:00","dateModified":"2024-06-20T11:17:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/"},"wordCount":1464,"commentCount":1,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg","keywords":["Calendar Design","Javascripts"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/","url":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/","name":"Create Your Own Advent Calendar with JavaScript - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg","datePublished":"2015-11-30T13:01:52+00:00","dateModified":"2024-06-20T11:17:35+00:00","description":"Advent marks a period of anticipation leading up to Christmas, starting four Sundays before December 25. Traditionally, this time is tracked using an","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/advent-calendar-javascript\/calendar-screenshot.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/advent-calendar-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Your Own Advent Calendar with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e","name":"Anna Monus","description":"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.","sameAs":["https:\/\/www.annalytic.com\/"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/anna_monus\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-6xU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=25166"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25166\/revisions"}],"predecessor-version":[{"id":72125,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25166\/revisions\/72125"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=25166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=25166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=25166"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=25166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}