Simple calendar using javascript
I would like to write all the dates, days and months of 2019 in JavaScript. By using 3 functions. I only found 1 function I could use but I don't get it to work out. Anyone have some ideas or tips? Thanks.
I need a function of NameOfTheMonths, NameOfTheWeekdays and DaysInAMonth. One function of each. No prints should be present in functions, all prints should be made in connection with the iterations.
document.writeln("Days in 2019 is:");
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for (var i = 0; i<=months.length; i++)
{
for (var k = 1; k<=31; k++)
{
document.write(months[i]);
document.writeln(k);
}
}
function rightAdjust(x, size)
{
x = "" + x; // secure that x is a string
var noOfBlanks = size - x.length;
var blanks = "";
for (var i = 0; i < noOfBlanks; i++)
{
blanks = blanks + " ";
}
return blanks + x;
}
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days;
days = DaysInAMonth(k);
for (var i = 0; i<=months.length; i++){
for (var k = 1; k<=days.length; k++)
{
document.write(months[i]);
document.writeln(days);
}
}
function DaysInAMonth(days)
{
var result;
if (months == [0])
{
return 31;
}
else if (months == [1])
{
return 28;
}
else if (months == [2])
{
return 31;
}
else if (months == [3])
{
return 30;
}
else if (months == [4])
{
return 31;
}
else if (months == [5])
{
return 30;
}
else if (months == [6])
{
return 31;
}
else if (months == [7])
{
return 31;
}
else if (months == [8])
{
return 30;
}
else if (months == [9])
{
return 31;
}
else if (months == [10])
{
return 30;
}
else if (months == [11])
{
return 31;
}
}
document.write(DaysInAMonth(1));
javascript
|
show 3 more comments
I would like to write all the dates, days and months of 2019 in JavaScript. By using 3 functions. I only found 1 function I could use but I don't get it to work out. Anyone have some ideas or tips? Thanks.
I need a function of NameOfTheMonths, NameOfTheWeekdays and DaysInAMonth. One function of each. No prints should be present in functions, all prints should be made in connection with the iterations.
document.writeln("Days in 2019 is:");
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for (var i = 0; i<=months.length; i++)
{
for (var k = 1; k<=31; k++)
{
document.write(months[i]);
document.writeln(k);
}
}
function rightAdjust(x, size)
{
x = "" + x; // secure that x is a string
var noOfBlanks = size - x.length;
var blanks = "";
for (var i = 0; i < noOfBlanks; i++)
{
blanks = blanks + " ";
}
return blanks + x;
}
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days;
days = DaysInAMonth(k);
for (var i = 0; i<=months.length; i++){
for (var k = 1; k<=days.length; k++)
{
document.write(months[i]);
document.writeln(days);
}
}
function DaysInAMonth(days)
{
var result;
if (months == [0])
{
return 31;
}
else if (months == [1])
{
return 28;
}
else if (months == [2])
{
return 31;
}
else if (months == [3])
{
return 30;
}
else if (months == [4])
{
return 31;
}
else if (months == [5])
{
return 30;
}
else if (months == [6])
{
return 31;
}
else if (months == [7])
{
return 31;
}
else if (months == [8])
{
return 30;
}
else if (months == [9])
{
return 31;
}
else if (months == [10])
{
return 30;
}
else if (months == [11])
{
return 31;
}
}
document.write(DaysInAMonth(1));
javascript
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
1
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13
|
show 3 more comments
I would like to write all the dates, days and months of 2019 in JavaScript. By using 3 functions. I only found 1 function I could use but I don't get it to work out. Anyone have some ideas or tips? Thanks.
I need a function of NameOfTheMonths, NameOfTheWeekdays and DaysInAMonth. One function of each. No prints should be present in functions, all prints should be made in connection with the iterations.
document.writeln("Days in 2019 is:");
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for (var i = 0; i<=months.length; i++)
{
for (var k = 1; k<=31; k++)
{
document.write(months[i]);
document.writeln(k);
}
}
function rightAdjust(x, size)
{
x = "" + x; // secure that x is a string
var noOfBlanks = size - x.length;
var blanks = "";
for (var i = 0; i < noOfBlanks; i++)
{
blanks = blanks + " ";
}
return blanks + x;
}
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days;
days = DaysInAMonth(k);
for (var i = 0; i<=months.length; i++){
for (var k = 1; k<=days.length; k++)
{
document.write(months[i]);
document.writeln(days);
}
}
function DaysInAMonth(days)
{
var result;
if (months == [0])
{
return 31;
}
else if (months == [1])
{
return 28;
}
else if (months == [2])
{
return 31;
}
else if (months == [3])
{
return 30;
}
else if (months == [4])
{
return 31;
}
else if (months == [5])
{
return 30;
}
else if (months == [6])
{
return 31;
}
else if (months == [7])
{
return 31;
}
else if (months == [8])
{
return 30;
}
else if (months == [9])
{
return 31;
}
else if (months == [10])
{
return 30;
}
else if (months == [11])
{
return 31;
}
}
document.write(DaysInAMonth(1));
javascript
I would like to write all the dates, days and months of 2019 in JavaScript. By using 3 functions. I only found 1 function I could use but I don't get it to work out. Anyone have some ideas or tips? Thanks.
I need a function of NameOfTheMonths, NameOfTheWeekdays and DaysInAMonth. One function of each. No prints should be present in functions, all prints should be made in connection with the iterations.
document.writeln("Days in 2019 is:");
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
for (var i = 0; i<=months.length; i++)
{
for (var k = 1; k<=31; k++)
{
document.write(months[i]);
document.writeln(k);
}
}
function rightAdjust(x, size)
{
x = "" + x; // secure that x is a string
var noOfBlanks = size - x.length;
var blanks = "";
for (var i = 0; i < noOfBlanks; i++)
{
blanks = blanks + " ";
}
return blanks + x;
}
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var days;
days = DaysInAMonth(k);
for (var i = 0; i<=months.length; i++){
for (var k = 1; k<=days.length; k++)
{
document.write(months[i]);
document.writeln(days);
}
}
function DaysInAMonth(days)
{
var result;
if (months == [0])
{
return 31;
}
else if (months == [1])
{
return 28;
}
else if (months == [2])
{
return 31;
}
else if (months == [3])
{
return 30;
}
else if (months == [4])
{
return 31;
}
else if (months == [5])
{
return 30;
}
else if (months == [6])
{
return 31;
}
else if (months == [7])
{
return 31;
}
else if (months == [8])
{
return 30;
}
else if (months == [9])
{
return 31;
}
else if (months == [10])
{
return 30;
}
else if (months == [11])
{
return 31;
}
}
document.write(DaysInAMonth(1));
javascript
javascript
edited Dec 29 '18 at 18:07
SlipsknuteN
asked Dec 28 '18 at 18:00
SlipsknuteNSlipsknuteN
33
33
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
1
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13
|
show 3 more comments
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
1
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
1
1
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13
|
show 3 more comments
1 Answer
1
active
oldest
votes
In JavaScript I would just use an object.
obj = {months:[
{name: "january", days: 31},
{name: "febuary", days: 28},
{name: "march", days: 31},
{name: "april", days: 30},
...
]}
and do some nested forEach()
and for
loops on the object with an array of weekday names and MOD on the array index of weekday names.
printyear(firstdayindex = 0) {
let days = ["mon","tues", "wed"....]
let currentday = firstdayindex;
obj.months.forEach((m) => {
for (int x = 1; x <= m.days; x++) { console.log(days[(currentday++)%7]+ x + m.name) }
})
}
But if you really want to abstract out into these functions, I am sure you can do something like this:
NameOfTheMonths() {
let names = ;
obj.months.forEach(m => {names.push(m.name);
return names;})
}
NameOfTheWeekdays() {//just return an array of names }
DaysInAMonth(month) {obj.months.findIndex(m=>m.name===month).days}
With more information on specifically what they should do I could probably add more but i would personally go about the task without those 3 functions and just operate on the object I describe above since the only input you would need is what day of the week the first day of the year is. Then you will have to do more work to piece the data back together from the 3 functions.
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962518%2fsimple-calendar-using-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In JavaScript I would just use an object.
obj = {months:[
{name: "january", days: 31},
{name: "febuary", days: 28},
{name: "march", days: 31},
{name: "april", days: 30},
...
]}
and do some nested forEach()
and for
loops on the object with an array of weekday names and MOD on the array index of weekday names.
printyear(firstdayindex = 0) {
let days = ["mon","tues", "wed"....]
let currentday = firstdayindex;
obj.months.forEach((m) => {
for (int x = 1; x <= m.days; x++) { console.log(days[(currentday++)%7]+ x + m.name) }
})
}
But if you really want to abstract out into these functions, I am sure you can do something like this:
NameOfTheMonths() {
let names = ;
obj.months.forEach(m => {names.push(m.name);
return names;})
}
NameOfTheWeekdays() {//just return an array of names }
DaysInAMonth(month) {obj.months.findIndex(m=>m.name===month).days}
With more information on specifically what they should do I could probably add more but i would personally go about the task without those 3 functions and just operate on the object I describe above since the only input you would need is what day of the week the first day of the year is. Then you will have to do more work to piece the data back together from the 3 functions.
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
add a comment |
In JavaScript I would just use an object.
obj = {months:[
{name: "january", days: 31},
{name: "febuary", days: 28},
{name: "march", days: 31},
{name: "april", days: 30},
...
]}
and do some nested forEach()
and for
loops on the object with an array of weekday names and MOD on the array index of weekday names.
printyear(firstdayindex = 0) {
let days = ["mon","tues", "wed"....]
let currentday = firstdayindex;
obj.months.forEach((m) => {
for (int x = 1; x <= m.days; x++) { console.log(days[(currentday++)%7]+ x + m.name) }
})
}
But if you really want to abstract out into these functions, I am sure you can do something like this:
NameOfTheMonths() {
let names = ;
obj.months.forEach(m => {names.push(m.name);
return names;})
}
NameOfTheWeekdays() {//just return an array of names }
DaysInAMonth(month) {obj.months.findIndex(m=>m.name===month).days}
With more information on specifically what they should do I could probably add more but i would personally go about the task without those 3 functions and just operate on the object I describe above since the only input you would need is what day of the week the first day of the year is. Then you will have to do more work to piece the data back together from the 3 functions.
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
add a comment |
In JavaScript I would just use an object.
obj = {months:[
{name: "january", days: 31},
{name: "febuary", days: 28},
{name: "march", days: 31},
{name: "april", days: 30},
...
]}
and do some nested forEach()
and for
loops on the object with an array of weekday names and MOD on the array index of weekday names.
printyear(firstdayindex = 0) {
let days = ["mon","tues", "wed"....]
let currentday = firstdayindex;
obj.months.forEach((m) => {
for (int x = 1; x <= m.days; x++) { console.log(days[(currentday++)%7]+ x + m.name) }
})
}
But if you really want to abstract out into these functions, I am sure you can do something like this:
NameOfTheMonths() {
let names = ;
obj.months.forEach(m => {names.push(m.name);
return names;})
}
NameOfTheWeekdays() {//just return an array of names }
DaysInAMonth(month) {obj.months.findIndex(m=>m.name===month).days}
With more information on specifically what they should do I could probably add more but i would personally go about the task without those 3 functions and just operate on the object I describe above since the only input you would need is what day of the week the first day of the year is. Then you will have to do more work to piece the data back together from the 3 functions.
In JavaScript I would just use an object.
obj = {months:[
{name: "january", days: 31},
{name: "febuary", days: 28},
{name: "march", days: 31},
{name: "april", days: 30},
...
]}
and do some nested forEach()
and for
loops on the object with an array of weekday names and MOD on the array index of weekday names.
printyear(firstdayindex = 0) {
let days = ["mon","tues", "wed"....]
let currentday = firstdayindex;
obj.months.forEach((m) => {
for (int x = 1; x <= m.days; x++) { console.log(days[(currentday++)%7]+ x + m.name) }
})
}
But if you really want to abstract out into these functions, I am sure you can do something like this:
NameOfTheMonths() {
let names = ;
obj.months.forEach(m => {names.push(m.name);
return names;})
}
NameOfTheWeekdays() {//just return an array of names }
DaysInAMonth(month) {obj.months.findIndex(m=>m.name===month).days}
With more information on specifically what they should do I could probably add more but i would personally go about the task without those 3 functions and just operate on the object I describe above since the only input you would need is what day of the week the first day of the year is. Then you will have to do more work to piece the data back together from the 3 functions.
edited Jan 2 at 10:59
Useless Code
8,46032635
8,46032635
answered Dec 28 '18 at 20:46
azythazyth
552215
552215
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
add a comment |
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
Thanks a lot for the help. I will try this!
– SlipsknuteN
Dec 29 '18 at 18:08
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
I edited the answer because that is an object literal, not JSON. There is not such thing as a JSON object.
– Useless Code
Jan 2 at 11:06
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
sure, it is just colloquial terminology
– azyth
Jan 4 at 21:12
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962518%2fsimple-calendar-using-javascript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What should those three functions return, and which arguments would they need to get? Did you get a template for them?
– trincot
Dec 28 '18 at 18:07
1
do your homework without cheating! ;-)
– Lelio Faieta
Dec 28 '18 at 18:10
Didn't get a template. I am not sure what you mean by which arguments they need to get. Sorry! :/
– SlipsknuteN
Dec 28 '18 at 18:11
I mean, you could just create three empty functions that take no arguments and return nothing, and do all the work outside of them. Obviously that is not what you are looking for. So could you describe what those three functions need to return? If you don't know, then how can we?
– trincot
Dec 28 '18 at 18:13
Wouldn't call it cheating. Not studying anything with programming but I need to understand it. Will have an oral exam in this so do not worry.
– SlipsknuteN
Dec 28 '18 at 18:13