# Lines inside the displayCatInfo() function

**URL:** <https://discourse.mozilla.org/t/lines-inside-the-displaycatinfo-function/97014>\
**Category:** Learn\
**Created:** [May 8, 2022, 4:34pm UTC](https://discourse.mozilla.org/t/lines-inside-the-displaycatinfo-function/97014 "2022-05-08T16:34:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelharold327](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@samuelharold327](https://discourse.mozilla.org/u/samuelharold327)\
**Post date:** [May 8, 2022, 4:34pm UTC](https://discourse.mozilla.org/t/lines-inside-the-displaycatinfo-function/97014/1 "2022-05-08T16:34:31Z")

</div>

Why are the `para1.textContent = motherInfo;` and `para2.textContent = kittenInfo;` lines inside the `displayCatInfo()` function, and not at the end of the script?

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [May 8, 2022, 11:45pm UTC](https://discourse.mozilla.org/t/lines-inside-the-displaycatinfo-function/97014/2 "2022-05-08T23:45:13Z")

</div>

Hi @samuelharold327

The `fetch()` method is asynchronous which means that the browser doesn’t wait for the result, but continues with the rest of the code. The `displayCatInfo()` function only get called when the results from `fetch()` arrive. Inside this function the two variables `motherInfo` and `kittenInfo` get their content.  
If the two line were outside the function the order would be:

- `fetch()` gets called
- The two line assign the original strings to `para1` and `para2`
- Results arrive and `displayCatInfo()` gets called
- `motherInfo` and `kittenInfo` receive their content, but aren’t assigned to the paragraphs (since this happened before)

Does that make it clear?

Have a nice day,  
Michael

---

<div class="post-metadata">

**Author:** ![samuelharold327](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@samuelharold327](https://discourse.mozilla.org/u/samuelharold327)\
**Post date:** [May 9, 2022, 2:03am UTC](https://discourse.mozilla.org/t/lines-inside-the-displaycatinfo-function/97014/3 "2022-05-09T02:03:22Z")

</div>

sangat jelas. terimasih 😀
