• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

277
Views
switch statement not load data in javascript

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;

})(); 

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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++;
  }
});

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error