Hello friends,

I have to create a dense array called "monthName that contains the names of all 12 months starting with "January" So far, I have created this:

function showDate(thisDate) {
    var thisWDay=Today.getWeekday();
    var thisDay=Today.getDate();
    var thisMonth=Today.getMonth();
    var thisYear=Today.getFullYear();
    var variable=new Array(monthName[0]="January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");}

I am really not sure if I did it right or not, and I need someone's input. Thank you. :)

Recommended Answers

All 4 Replies

Not sure what you mean... How about this...

var monthName = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

Would that be simplier?

It told me to set up the array so that monthName[0]="January"

I was wondering where I would place that. :\

OK, so how about this...

var monthName = new Array(12)
// the current value of monthName is [undefined, undefined, ...]
monthName[0] = "January"
// when you check the value of the array, it will be...
// ["January", undefined, undefined, ...]

I'm not sure how much knowledge you have about array data type. The first line is to declare an array data type to the variable named monthName. At the same time, the declaration assign the array size (12). Once declare an array with the size, the default value of each element the array is holding is undefined. Then the second line assigns value "January" to the first index (0) of the array.

Right, that makes a little more sense. The book I am learning from (I'm doing homework for my own benefit) was a bit vague in explaining dense array, but when you arranged it like that it made more sense. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.