can we use in switch and logical && her the code first it work will and after few minutes it stop and don't recognize the error and searched in google & youtube etc don't found any sol
const url =
"https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.json";
async function getData() {
const response = await fetch(url);
const data = await response.json();
return data;
}
function getResults(data) {
const results = {
confirmed: 0,
suspected: 0,
England: 0,
};
data.forEach((person) => {
switch (person.Status & person.Country) {
case "confirmed":
results.confirmed ++;
break;
case "suspected":
results.suspected ++;
break;
case "England":
results.England ++;
break;
default:
break;
}
});
return results;
}
(async function () {
const data = await getData();
const results = getResults(data);
console.log(
`${results.confirmed} confirmed cases\n${results.suspected} suspected cases.`
);
document.getElementById("vocs").innerHTML = results.confirmed;
document.getElementById("voxsus").innerHTML = results.suspected;
document.getElementById("gr").innerHTML = results.confirmed + results.suspected;
})();
An if/else
statement is sufficient.
data.forEach((person) => {
if (person.Status && person.Country) {
if (person.Status === 'confirmed') results.confirmed++;
if (person.Status === 'suspected') results.suspected++;
if (person.Country === 'England') results.England++;
}
});