How to print the numbers of the calendar in a table?

JS collected all the data, it remains only to draw the final table with the calendar. I can not understand how to skip the first 3 table cells in the first row if the month starts on Thursday and post the first number is with 4 cells and after the 7th to make a "newline". The implementation looked different, for example:
do {
 // Start table row
 if (index%7==0) {
tmp+=";
}
 // Empty cell to the beginning of the month or at the end
 if ((index<start_day) || (index>=(total_days+start_day))) {
 tmp+=' <\/td>';
 }</start_day)>

or
for (c=8;c<43;c++)
if (td_d[c].innerHTML==0) {
 td_d[c].visibility="hidden"; // do not show cell if it's empty
} else td_d[c].bgColor="white"; // non-empty cell to paint white color

But th somehow does not reach me the algorithm anyway.
July 9th 19 at 14:04
2 answers
July 9th 19 at 14:06
Solution
Try easier.
You have an array of 31 elements, you know that the month starts with Thursday.
Add at the beginning of the array 3 an empty element and output by a simple scheme as if the month starts on Monday.
Yeah, great idea, thanks! How to determine the numbers that are under the SAT and sun (in the columns) and make them red (output)? - Clovis_Gulgowski43 commented on July 9th 19 at 14:09
Depends on how you will withdraw.
If the two cycles, rows, columns, then the column number (or row, depending on how you take it). - Daphne_Roob commented on July 9th 19 at 14:12
If just the number element, something like (i+1) % 7 == 0 is the sun, (i+2) % 7 == 0 is SAT. - Daphne_Roob commented on July 9th 19 at 14:15
July 9th 19 at 14:08
Solution
var crm = dt.getMonth();
var sdt = new Date(dt.getFullYear(), crm, 1, 9, 1, 1);
var day = sdt.getDay();
if (day != 1) sdt.setDate((day == 0) ? -5 : -(day - 2));
var cl = 0, tr = null, td, nmn,
secoffs = 24 * 60 * 60 * 1000,
vof = sdt.valueOf();
for (var i = 0; i < 42; i++){
 if (!cl){
 tr = pr._crEl('tr');
 pr._addChild(bd, tr);
}
 var ndt = new Date(vof + (secoffs * i));
 td = pr._crEl('td');
 pr._addChild(tr, td);
 td.innerText = ndt.getDate();
 nmn = ndt.getMonth();
 if (nmn != crm) pr._setAttrs(td, { "class": "wch-cal-ncm", 'data-month': nmn, 'data-year': ndt.getFullYear() });
 if (++cl > 6) cl = 0;
}
That's fine, but I would like to understand, not to find a ready-made solution ) - Clovis_Gulgowski43 commented on July 9th 19 at 14:11
: getDay() - returns the day of the week to the first day of the month. This will be the offset. - Daphne_Roob commented on July 9th 19 at 14:14
And this code in normal offices hands off... It is completely unreadable. - Daphne_Roob commented on July 9th 19 at 14:17
: Why cycle to 42 goes? - Clovis_Gulgowski43 commented on July 9th 19 at 14:20
: Me in personal projects don't need the code readability and comments. I read your code easily and using for many years. - candida_Upton commented on July 9th 19 at 14:23
: Is the month in which a month is 6 weeks - Gertrude.Mueller commented on July 9th 19 at 14:26
And then of personal projects you carry this code with readability in working... - Clovis_Gulgowski43 commented on July 9th 19 at 14:29
: This is your personal approach? - candida_Upton commented on July 9th 19 at 14:32
: Well, You only that rekomendovali this code man and he'll probably put it into production. And someone else will have to support it. I think it will not add points to the project. - candida_Upton commented on July 9th 19 at 14:35
: I can't insert this code in the project though, because I cannot understand it )) I put in at least what he figured out - Clovis_Gulgowski43 commented on July 9th 19 at 14:38
: Exactly. Most do the same. - candida_Upton commented on July 9th 19 at 14:41
: Smart people don't do thoughtless copypasted content. - Gertrude.Mueller commented on July 9th 19 at 14:44
But don't waste time sorting and tidying the code. And there are places where such fire. He saw. - Clovis_Gulgowski43 commented on July 9th 19 at 14:47
: And again, I did not want to denigrate Your work. I just recommend to improve programming style before it's too late and You will lose something because of this. - candida_Upton commented on July 9th 19 at 14:50
: Which is? ))) For your own projects, saving on bandwidth, for commercial you even seen. For C#, java, javascript, C++, python? To recommend something is when you know something about the person. - candida_Upton commented on July 9th 19 at 14:53

Find more questions by tags JavaScript