So I got this problem for my chrome extension:
function comparingDates(fn) {
var currentDate = new Date();
var j;
chrome.storage.sync.get("storeDates", function comparing(items) {
if (!chrome.runtime.error) {
var arrayDates = items.storeDates;
var i = 0;
do {
if (arrayDates[i].date == currentDate.getDate()) {
j = i; // problemas al enviar el j
};
i++
} while (!j);
fn(j);
};
});
};
var currentDay;
comparingDates(function (l1) {
if (!l1) {
console.log("error");
} else {
currentDay = l1;
console.log("succes");
};
storeDates object contains multiple dates, which are compared with the currentDate. When the do/while loops find a match it suppose to assign j a value. But for some reason when the callback is sent the assignment for currentDay is not made.
I try to get a hold of the callback theory and implemented to my code, but mostly all the examples i could find just print the result instead to assign to a certain value. Any suggestions on how to fix this problem