Assessment wanted for JSON skill test__

Json skill test

I would be grateful if someone can assess my code for JSON skill test. plus I had a doubt -

  • Why are the para1.textContent = motherInfo; and para2.textContent = kittenInfo; lines inside the displayCatInfo() function, and not at the end of the script? This has something to do with async code.
    I did not understand this part in mdn article

Welcome back, @shraddhav1935

Nice work. This is mostly correct. :clap:

Something that’s missing is:
You should count the kittens in your loops and then output how many are in total, male and female.

About the additional question:
The reason is that fetch() is asynchronous. After it is called it will take some time until the result arrives and displayCatInfo() is executed. While waiting for the result, JavaScript will continue with the rest of the code.
If those assignments where outside the function, they would be executed before the fetch results arrive and won’t have all the cat names and such in it.

Does that make it clearer?


It does make it clearer.
Updated my code.
Thank you so much!

1 Like

Great improvements!
Now everything is correct.