Hello, please I’ll like for you to assess my submission, your tips and suggestions will help me a lot.
Thanks for helping me improve !
https://github.com/ikennarichard/mdn-active-learning/blob/main/test-1.js
Hello, please I’ll like for you to assess my submission, your tips and suggestions will help me a lot.
Thanks for helping me improve !
https://github.com/ikennarichard/mdn-active-learning/blob/main/test-1.js
Hi @kenna and welcome to the community
Well done!
Here are some tips to make the code simpler:
male++
and female++
.kittenInfo
line can go outside the inner loop. It’s fine to assign the string once after we are finished counting.motherInfo
instead of using an additional loop.Do you have an answer for this?
Why are the
para1.textContent = motherInfo;
andpara2.textContent = kittenInfo;
lines inside thedisplayCatInfo()
function, and not at the end of the script? This has something to do with async code.
Keep up the great work!
Michael
Hello @mikoMK thanks a lot for the superpowers. For the question, i think is because we dont want textcontent set to the initial values. not sure. Thanks agian! for the review
Yes, that’s right. The interesting point is why it would be empty. After all, the assignment is placed after the displayCatInfo()
function. So one may assume that the assignment also happens after the function run.
This is not the case because fetch()
is an async function. After asking the server for the JSON file it hands over the control to the rest of the code while it is waiting for the result. If the assignments were outside the displayCatInfo()
function, they would then be filled with the initial values. When the JSON arrives from the server, it would already be to late and any changes to motherInfo
and kittenInfo
wouldn’t have an effect.
That’s the fun with async code. Very useful, but needs some time to fully understand.
Well said Michael, your the best!