Hello, I would like an assessment on my solution for exercise on https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON
Thank you very much.
Karlo
My code:
function displayCatInfo(catString) {
let total = 0;
let male = 0;
// Add your code here
female = 0;
let catsInfo = JSON.parse(catString);
if(catsInfo.length < 1) {
return;}
let curFam;
let catSeparator = “,”;
for(let i = 0; i < catsInfo.length; i++) {
curMom = catsInfo[i].name;
switch(i){
case 0:
motherInfo += ${curMom}
;
break;
case catsInfo.length-1:
motherInfo += and ${curMom}
;
break;
default:
motherInfo += , ${curMom}
;
}
total+= catsInfo[i].kittens.length;
catsInfo[i].kittens.forEach(kitten=> {
male+= kitten.gender == “m” ? 1 : 0;
female+= kitten.gender == “f” ? 1 : 0;
});
kittenInfo = Number of kittens is ${total} of which are ${female} females and ${male} males.
;
}