Help required for JSON skill test

Hi everyone. can somone have a look at my code it seems to work ok, but just want to make sure if it is written in acceptable way.

here is my code .

let allKittens = 0;
let fKittens = 0;
let mKittens = 0;
let catInfo = JSON.parse(catString);
for(let i = 0; i < catInfo.length; i++){
if(i === catInfo.length - 1){
motherInfo += 'and ’ + catInfo[i].name + ‘.’;
}else{
motherInfo += catInfo[i].name + ', ’
}

const kittens = catInfo[i].kittens;
for(let j = 0; j < kittens.length; j++) {
   allKittens += 1;
    if(kittens[j].gender === 'm'){
        mKittens += 1;
    } else if(kittens[j].gender === 'f') {
        fKittens += 1;
    }
}

kittenInfo = 'We have total of ' + allKittens + ' kittens, ' + fKittens + 'female kittens and ' + mKittens + ' male Kittens.'

}

here is the test: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON

thanks.

This is what I got:

function displayCatInfo(catString) {
  let total = 0;
  let male = 0;

  // Add your code here

  const cats = JSON.parse(catString);

  for (i = 0; i < cats.length; i++){
    if (cats.length - i > 2){
     motherInfo+= `${cats[i].name}, `;
    } else if (cats.length - i === 2){
     motherInfo+= `${cats[i].name}`;
    } else {
     motherInfo+=` and ${cats[i].name}`;
    }
    
    for (j = 0; j < cats[i].kittens.length; j++){
      total += 1;
      
      if (cats[i].kittens[j].gender === 'm'){
        male=male+1;
      } 
    }
  }

  kittenInfo = `There are a total of ${total} kittens. ${male} of them are male, ${total-male} are female.`

// Don't edit the code below here!

  para1.textContent = motherInfo;
  para2.textContent = kittenInfo;
}

I was a bit confused about how to render the JSON at first, even though it says in the article it was going over my head. I was able to use your solution to eventually break it down and understand. Not a massive fan on the in page editor either as it’s harder to spot bugs and my loops weren’t working for ages because I was looking for m instead of ‘m’