In this video, what we're going to do is, weare going to combine our use of the date object with our new information aboutarrays that will allow us to determine days the week.
Actually write the wordMonday if it's Monday write out the word July if it's July and actually makeour dates a little bit more user-friendly.
So what we're going to do iswe're going to set up a couple of date objects and we're going to set up a coupleof arrays and we're going to use those to just do a couple of differentexamples.
So I'm going to go ahead and var todayIs again, and we're going to setthat equal to new date() which will retrieve today's date.
Let's go ahead andset up the birthday again and let's set that equal to a new date and go aheadand fill in my birthday again, August 6 1971.
And let's go ahead and set up two arrays one array is going to contain the daysof the week and a second is going to contain the names of the month.
Now I'vepre-typed these and i'm just going to paste them in so you don't have to watch metype all these, but just know that you're setting up the name of the array as anarray and then you're going to feed it in the days of the week and it looks likeI've missed some quotes along the way so I can just correct that real quick.
SoSunday's going into the zero-th spot, Saturday's going in the sixth spot of dayNames and then here in the months we'll have the same thing.
January's going intothe zero-th spot and December is going into the 11th spot.
So we're going tojust do a couple of, couple of examples where we retrieve the month and the dayand we write out those things using our array.
And then also, I'll figure out whatday of the week I was born.
All right, so let me go ahead and put some semicolons on the ends of those too.
did I just paste it in, and let's go aheadand get, oops, no semicolons.
So I don't know what I'm doing.
I was sitting up thosemanually take those semicolons off because we're setting up new arrays.
Alright, so let's go ahead and set up a variable and let's say todayName.
It'sgonna be equal to todayIs.
Now remember, thisis going to retrieve a value from 0 to 6 but corresponds, or will correspond, toour array.
Let's do the same thing with month.
Let's say var todayMonth is goingto be equal to todayIs.
GetMonth() Now remember, that one is alsogoing to retrieve a number from 0 to 11 which will allow us to retrieve theright thing.
So we've taken the.
we retrieved the index for our array, so nowall we have to do is go into the array and pull out the appropriate word.
And sowe're going to go ahead and document.
Write() "Today is " and we are going toretrieve.
so we're going to spell it out.
We're gonna say, "Today is July 28th, 2014".
So we're going to say, go into the array named month names, and I want you toretrieve what is stored in the todayMonth slot.
Remember our variable.
Our array is named monthNames.
We've retrieved the numberfrom 0 to 11 that corresponds with today's month and it'll go in there andfind it according to this variable.
so that'll say Janu.
So we're going concatenate on the date.
So we're just going to say, (coughing) excuseme, todayIs.
GetDate() because we're getting the date.
So it's going to sayJuly 28 plus we need to add in a comma because we usually say July 28, plus todayIs.
GetFullYear() Now, notice I can actuall, y instead of storingthese in variables, if I'm just going to use them once, it might be easier for me tojust go ahead and do them that way.
You need some parentheses here and Ineed some parentheses here because those are method.
All right, now if Iwanted to add the day of the month, I could go ahead and add that in here.
I'msorry the day of the week.
If I wanted to say that today is Monday, July 28th, Icould type in dayNames, go into there and find what's in the in the todayNamespot, add a comma, and then add the month.
So it's going to say today is Monday, July 28, 2014.
it looks like I have anerror somewhere.
I bet I forgot to close my parentheses on the end of thedocument.
So let's go ahead and take a look at that and see through allof that code we get our statement, "Today is Monday, July 28, 2014".
Now notice thosecommas don't have spaces like we would want so that's easily fixed.
We go backin, we put a space in after the comma to make it look like we want it to look.
Sothat's how you write out what seems like a very easy thing.
We need to concatenate a space in there also.
It seems like a very easy thing to do but it's actuallya fairly complex thing.
Let's go ahead and do.
let me go ahead and just get ridof that code that we did.
And just do one more thing.
Let's figure out what day ofthe year, I'm sorry day of the week I was born on.
So I'm going to go ahead and set up a variable called myDay and that's going to be equal to bday.
GetDay() So that returns what day of the week, from 0 to 6, that August 6th 1971 fell on.
Again very impressive that it can figure out thatusing the math that'd be very difficult for us to do.
And so then all we have todo is document.
Write() "I was born on a " and we add in, wetell it to go into the dayNames array and retrieve what is stored in the myDayslot.
So we preview that and it tells us that I was born on a Fridaywhich happens to be true.
There is a lot more to be learned.
If you're more into.
if you'reinterested, there are tons of tutorials out on the web and there are some goodtextbooks if you're interested just send me an email and I'll help you findsomething.