I’m fairly new to Google Apps Script and I may be missing something, but I’m trying to make a very basic script for testing purposes and literally everything I write runs twice. Absolutely no idea why. Can someone point me in the right direction for some reading I can do on this?
Right now, I’m just working with the Calendar API and getting the names of my calendars, but they always print twice. Here is the code:
function myFunction() {
let calendars = CalendarApp.getAllCalendars();
let haveCalendar = false;
for(i=0;i<calendars.length;i++){
if (calendars[i].getTitle() == "Holidays"){
Logger.log(calendars[i].getTitle());
haveCalendar = true;
} else if (haveCalendar == true || calendars[i].getTitle() != "Holidays"){
Logger.log("already have calendar");
}
}
}
myFunction();
The current output for this is:
already have calendar
already have calendar
Holidays
already have calendar
already have calendar
already have calendar
Holidays
already have calendar
I’m completely baffled. Any help would be greatly appreciated.
Thanks in advance!