How can I write a program in JavaScript that prints a calendar for a month by promoting the user to input both year and month? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I write a program in JavaScript that prints a calendar for a month by promoting the user to input both year and month?

The leap years should be taken in consideration

1st Jun 2018, 4:21 PM
Lina
2 Answers
+ 1
Something a bit crazy 😀: Check this page https://en.m.wikipedia.org/wiki/Determination_of_the_day_of_the_week So you know now what week day, e.g. the first/each day of the chosen month, is... Then make an array of number of days in each month, consider leap years (if not included in the algorithm already), check whether the week starts with Sun or Mo(o)n, and then, using, e.g. a for loop, get and format the output as a matrix with 7 rows/columns... 😂 OR Date.prototype.getWeekDay = function() { var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; return weekday[this.getDay()]; } and call date.getWeekDay(); 😀 OR just google it and find your favorite solution...
1st Jun 2018, 5:42 PM
Jiří Bočan
0
Thank you, means alot 😃
2nd Jun 2018, 7:01 AM
Lina