From the course: JavaScript for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Add the date

Solution: Add the date - JavaScript Tutorial

From the course: JavaScript for Web Designers

Start my 1-month free trial

Solution: Add the date

(upbeat music) - [Instructor] Let's walk through one possible solution to this challenge. First we'll prove that it actually works, it is indeed December 5th at the moment and this is the time, which was working before and hasn't broken since then. What a relief. All right, let's take a look at the code. First of all, I'm storing a reference to that currentDate area, using document.getElementById here. And then along with hours, minutes and AM, PM, I'm getting the month and the date using getMonth and getDate. Now the month that I get back from getMonth is a number and I want to format it as a word, so I have a little helper function called formatMonth that we'll take a look at in a second, that's going to handle that reformatting for me. And then down here, I'm using textContent to change the contents of that currentDate area, because I don't need to use HTML. So I just have the month, followed by a space,…

Contents