Assessment wanted for JSON skill test. (Task 1)
Link to task: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON#json_1
Link to my code:
Task-1: https://jsfiddle.net/EiNzp/cz695mou/14/
Thanks
Assessment wanted for JSON skill test. (Task 1)
Link to task: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_JSON#json_1
Link to my code:
Task-1: https://jsfiddle.net/EiNzp/cz695mou/14/
Thanks
Hi again, @EiN
Great work! Here are some comments:
cats.length
to decide what to put after the name. The wrong approach would be to use fixed numbers likeif (i === 2) {
motherInfo += `${cats[i].name}.`;
}
${total - male}
).motherInfo
and kittenInfo
are declared outside the function (at the beginning of the given code). So assigning the values from inside does indeed work. The actual problem is that fetch()
is an asynchronous function. If the assignments were outside displayCatInfo()
, they would happen before the results from fetch()
arrives and the function is called.I hope my explanations make sense.
Michael
I am glad that I was able to make the right decision for this task.
About simplifying ākitten counterā. Everything is clear, I just needed to think a little more.
Regarding the asynchronous function.
I have read the following articles:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function#try_it
and
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch.
To be honest, the understanding of these things has not yet fully come. I think that in the future, when I use asynchronous functions, with experience of use, a greater understanding will come, while everything is very superficial. I hope that further, in the next lessons, this topic will be revealed a little deeper and with practical tasks.
Yeah, asynchronous JavaScript is a bit hard to understand at the beginning, but I think the lessons about this topic are well made. It certainly is a very interesting topic (at least to me ). Iām pretty sure youāll eventually understand it.