I receive an error Uncaught TypeError: thisDay.setFullYear is not a function while attempting to modify the values.
I've attempted debugging in various stages of the code and have confirmed that I am able to access the thisDay variable from within my moveDate function, it just does not allow me to use any date functions on it.
My code I have been fighting with is located at https://jsfiddle.net/ramseys1990/g9cp42bj/3/
The snippet of the main problem is:
function moveDate(selection) {
switch(selection) {
case "prevYear":
thisDay.setFullYear((thisDay.getFullYear() - 1).toInteger);
putCalendar(thisDay.getMonth(), thisDay.getFullYear() - 1);
break;
case "prevMonth":
thisDay.setMonth(thisDay.getMonth() - 1);
//putCalendar(thisDay.getMonth() - 1, thisDay.getFullYear());
break;
case "nextMonth":
thisDay.setMonth(thisDay.getMonth() + 1);
//putCalendar(thisDay.getMonth() + 1, thisDay.getFullYear());
break;
case "nextYear":
thisDay.setFullYear(thisDay.getFullYear() + 1);
//putCalendar(thisDay.getMonth(), thisDay.getFullYear() + 1);
break;
case "today":
thisDay = new Date();
//putCalendar(thisDay.getMonth(), thisDay.getFullYear());
break;
}
putCalendar(thisDay.getMonth(), thisDay.getFullYear());
return;
}
My putCalendar function is:
function putCalendar(month, year) {
// Set the date displayed in the calendar
thisDay.setMonth = month;
thisDay.setFullYear = year;
// Determine the current month
//var thisMonth = thisDay.getMonth();
// Determine the current year
//var thisYear = thisDay.getFullYear();
// write the calendar to the element with the id 'calendar'
document.getElementById("demo").innerHTML = createCalendar(thisDay);
}
And the top of my code file is currently:
"use strict";
var thisDay = new Date();
putCalendar(thisDay.getMonth(), thisDay.getFullYear());
I expect it to pass the modified date to my putCalendar function to recreate the calendar for a different year or month.
The problem is that here
putCalendar(thisDay.getMonth(), thisDay.getFullYear());
you call getFullYear
and its return value gets passed to putCalendar
, which is not a function .
Then year
, and .setFullYear
will get this value, and when you try to call it, it will fail.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.