# Assessment wanted for my JSON skill test

**URL:** <https://discourse.mozilla.org/t/assessment-wanted-for-my-json-skill-test/87408>\
**Category:** Learn\
**Tags:** learning\
**Created:** [October 17, 2021, 10:39am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-my-json-skill-test/87408 "2021-10-17T10:39:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jurggjon](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jurggjon](https://discourse.mozilla.org/u/jurggjon)\
**Post date:** [October 17, 2021, 10:39am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-my-json-skill-test/87408/1 "2021-10-17T10:39:03Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON). Thank you in advance!

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [October 17, 2021, 12:37pm UTC](https://discourse.mozilla.org/t/assessment-wanted-for-my-json-skill-test/87408/2 "2021-10-17T12:37:14Z")

</div>

Hi @jurggjon and welcome to the community! 👋

Congratulations on your work! Your code works as expected. Nice usage of the `for...of ` loop. 🏅

Two remarks:

- You should use `const` in your variable definitions (e.g. `const cats = ...`) otherwise they end up in the global scope.
- About code style: I recommend writing loops and `if`s with curly braces and on new lines even when they are only one line long. It improves readability and makes it less error-prone. Of course this is just an opinion as your code works with those one-liners.

I hope this feedback helps. Feel free to ask questions or come back with more tasks to be assessed. 🙂

Happy coding!  
Michael

PS: Your email address is visible in your post. I think it somehow ended up in the optional “name” field of your profile. I recommend removing it.
