JSON1 (https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON)

i read article on working with json and i not get proper understanding on that so anyone can provide me solution of working with json (test your skills) => “json1” . i want solution.

which part that you do not understand :slight_smile:

hello can you give me solution

check this post :slight_smile:

Hi there @digitalparesh! You can find the solution here: https://github.com/mdn/learning-area/blob/master/javascript/oojs/tasks/json/marking.md

1 Like

Thank you @chrisdavidmills i got it solution.

sorry i just discoverd i did not post the link

glad that @chrisdavidmills helped

have a nice day both of you

1 Like

Hi,

I didnt like the comma just before the and so put in an if else to the cats section. My code was as follows.

newText = JSON.parse(catString);
for (let i = 0; i < newText.length; i++) {
if (i === newText.length - 1) {
motherInfo += ’ and ’ + newText[i][‘name’] + ‘.’;
} else if (i === newText.length - 2) {
motherInfo += newText[i][‘name’];
} else {
motherInfo += newText[i][‘name’] + ', ';
}

for (let j = 0; j < newText[i][‘kittens’].length; j++) {
total += 1;
if (newText[i][‘kittens’][j][‘gender’] === ‘m’) {
male += 1;
}

}

}

kittenInfo = There are ${total} kittens and ${male} are male and ${total - male} are female

1 Like

why did not use for of in this case?

1 Like

Hi @samuelharold327
I got to admit. I haved coded for over a year now having taken up yoga. Its good stuff btw. I have forgotten most of my code and the strange thing is I decided to come back and finish it today. Maybe the universe is telling me something. Isvara Pranidana as they say in yoga (surrender to the universe). I will have a look and see if I can remember my code Samuel.

Also welcome to Mozilla. I learnt a lot here and I am sure you will too. :smile:

1 Like

Hi @samuelharold327

Using for..of for the inner loop would be a good idea. For the outer loop I think it’s fine to use a traditional loop since we need the index to decide if we are at the last element.

If you have more questions or have exercises that you want us to have a look at, feel free to come back. We are here to help. :slightly_smiling_face:

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.

1 Like