Hi, I wanted assessment with this code:
const section = document.querySelector('section');
let para1 = document.createElement('p');
let para2 = document.createElement('p');
let motherInfo = 'The mother cats are called ';
let kittenInfo;
fetch('sample.json')
.then(response => response.text())
.then(text => displayCatInfo(text))
function displayCatInfo(catString) {
let total = 0;
let male = 0;
// My code here
cats = JSON.parse(catString);
for (cat of cats) {
if (cats.indexOf(cat) == cats.length - 1) motherInfo += `and ${cat.name}.`;
else motherInfo += `${cat.name}, `;
total += cat.kittens.length;
for (kitten of cat.kittens) if (kitten.gender === "m") male++;
}
female = total - male;
kittenInfo = `The total number of kittens is ${total}, of which ${male} are male and ${female} female.`;
// Don't edit the code below here!
para1.textContent = motherInfo;
para2.textContent = kittenInfo;
}
section.appendChild(para1);
section.appendChild(para2);
The link the test is referring to is: Test your skills: JSON. Thank you in advance!