Assessment wanted for JSON 1

So I finished the JSON 1 assessment (mostly) and this is what I did at first:

I knew I had to combine all of the kitten arrays to get the total number of kittens so I stored each array in a new variable and used the spread operator to combine them. However, I took another look at the instructions in the article and saw I could just nest for...of loops together to get to the kitten arrays. I edited my code and here’s the final result:

I just wanted a little feedback on how I did and what I can do to improve. Any thoughts?

Link to my code: JSON practice (codepen.io)

Hi @gijutaku23

Great work! :tada:

Using a nested loop seems indeed nicer to me. Counting the kittens might be a bit cleaner with increments in the loop:

for (const kitten of cat.kittens) {
  total++;
  if (kitten.gender === 'm') {
   male++;
  }
}

… but that’s probably more a matter of taste. :grin:

Happy New Year,
Michael

1 Like