Apoligies for my basic understanding of jQuery. I am trying to write a function that can have values set by the user or left blank, set themselves. It looks like this:
// Calendar
function eventCalendar(yearSet, monthSet) {
// Get current date
var date = new Date();
// Check to see if variables were set in function
// Year
if ((yearSet.length > 0)) {
var year = yearSet;
} else {
var year = date.getFullYear();
}
// Month
if ((monthSet.length > 0)) {
var month = monthSet;
} else {
var month = date.getMonth();
}
console.log(month + ', ' + year);
}
However when the function is called without variables, console sends me the error:
‘yearSet is undefined’
How do I get around this?
You can simplify your method like this.