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’