Assessment wanted for JSON skill test. (Task 1)

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 :wink:

Hi again, @EiN

Great work! Here are some comments:

  • Regarding your first comment. You did the right thing by using cats.length to decide what to put after the name. The wrong approach would be to use fixed numbers like
    if (i === 2) {
      motherInfo += `${cats[i].name}.`;
    }
    
  • You could make the ā€œkitten counterā€ simpler by only counting one gender and calculating the other in the template string (e. g. ${total - male}).
  • Your reasoning in the second comment is wrong. The two variables 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. :slightly_smiling_face:

Michael

1 Like

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. :slightly_smiling_face:

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.

1 Like

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 :slight_smile:). Iā€™m pretty sure youā€™ll eventually understand it.

1 Like