My goal is to track the occurrences of four specific string values within the same key.
The issue lies in my struggle with adding multiple counters. While the first counter successfully tracks the initial condition, subsequent conditions within the if/else statement impede the proper counting of all conditions. This data is sourced from a Promise.all
that includes various URLs.
Below is my code snippet:
const urls = [
'https://api.github.com/users/TylerP33/repos?page=1',
'https://api.github.com/users/TylerP33/repos?page=2',
// more URLS here...
];
function getLanguages() {
return Promise.all(urls.map(url =>
fetch(`${url}`)
.then(response => response.json())
.then(obj => obj.forEach(function(val) {
let rubyCounter = 0;
let cssCounter = 0;
let htmlCounter = 0;
let jsCounter = 0;
if (val.language === "Ruby") {
rubyCounter++;
console.log(rubyCounter);
}
})))
)
}
getLanguages();
rubyCounter
correctly displays 235
, but introducing additional conditions seems to disrupt the counting process due to the true/false conditions affecting the same key. I may be overlooking something obvious and would appreciate your input on this matter.
Thank you in advance.