I am trying to create a logic switch in Javascript. The aim is to create a Javascript function which can be used to trigger an even on a button click and turn specific calendar feed on or off. When you click button for the first time it should load the calendar feed, when the same button is clicked for the second time the feed should be turned off, and on if its clicked third time etc.
This is the code so far :
function click1() {
if (times11 % 2 == 0 )
{$("#calendar").fullCalendar( 'addEventSource', {url: 'https://www.google.com/'});
times11++;
}
else
{$("#calendar").fullCalendar( 'removeEventSource', {url: 'https://www.google.com/'});
times11++;
}
}
For a reason I am uncapable of figuring out it increments by 2.
Ps: var times11 is defined above using var times11 = 0;
1 Answer