# Assessment wanted for Functions 1 test

**URL:** <https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611>\
**Category:** Learn\
**Created:** [April 7, 2022, 2:08am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611 "2022-04-07T02:08:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torvous](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@Torvous](https://discourse.mozilla.org/u/Torvous)\
**Post date:** [April 7, 2022, 2:08am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611/1 "2022-04-07T02:08:13Z")

</div>

Hey there, I need help invoking the function.  
I’ve stored the value for the array index in namesIndex variable, and I’ve tried returning the names with return names[namesIndex]; but I’ve got no results.

I’ve seen that on MDN Github the solution was storing the variable to  
para.textContent but I don’t get it, can someone explain how does para.textContent work?  
Is there an alternative way to solve this by using return as stated in my example?

See the Pen [Functions 1](https://codepen.io/torvvous/pen/PoERpWx) by Torvvous ([@torvvous](https://codepen.io/torvvous)) on [CodePen](https://codepen.io).

---

<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:** [April 7, 2022, 3:22am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611/2 "2022-04-07T03:22:55Z")

</div>

Hi @Torvous and welcome to the community 👋

> [@Torvous](#):
>
> can someone explain how does para.textContent work?

I’ll try my best. 😄

With `textContent` we can add text inside a HTML tag. On line 30 of your code you see that we are creating a `<p>` element with the name `para`. By using `para.textContent = ...;` we write the name found in the array into the `<p>`. Finally the `<p>` will be added to the existing section of the HTML. In the end the HTML will look something like this:

```auto
<section class="preview">
  <p>Tina</p> /* or whatever name was calculated by the function */
</section>

```

The whole idea of the `textContent` thing is that we can see the result of our JS code in HTML. When using `return` you need to also assign the returned value to a variable. You could do this: `const name = chooseName();` to save the name from the function into the variable `name`. But then you still don’t know if your function works correctly because you can’t see the value in the variable. Beside `textContent` you could also use `console.log(name);` to write the name to the console of the DevTools.

This `textContent` method will be used in several other task to display the result of your calculations.

I hope my explanation didn’t confuse you more. Feel free to tell me if something isn’t clear, yet. 🙂

Have a nice day,  
Michael

---

<div class="post-metadata">

**Author:** ![justsomeone](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/justsomeone/32/67787_2.png) [@justsomeone](https://discourse.mozilla.org/u/justsomeone)\
**Post date:** [April 7, 2022, 11:04am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611/3 "2022-04-07T11:04:09Z")

</div>

Hello @Torvous @mikoMK

just a little thing for the TextContent property that i think you should read this

> **[Node: textContent property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent)**
>
> The textContent property of the Node
> interface represents the text content of the node and its descendants.

> **[HTMLElement: innerText property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText)**
>
> The innerText property of the HTMLElement interface represents the rendered text content of a node and its descendants.

> **[Element: innerHTML property - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML)**
>
> The Element property innerHTML gets or sets the HTML or XML markup contained within the element.

case textContent and innerText and innerHTML are easily get confused specialy the first 2 of them

and have a nice day both of you 🙂

---

<div class="post-metadata">

**Author:** ![Torvous](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@Torvous](https://discourse.mozilla.org/u/Torvous)\
**Post date:** [April 8, 2022, 11:53am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611/4 "2022-04-08T11:53:04Z")

</div>

Thank you so much for your explanation, it is very clear and it makes much more sense now. I’ve tried the solutions on an editor and it works now. Have a good day!

---

<div class="post-metadata">

**Author:** ![Torvous](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@Torvous](https://discourse.mozilla.org/u/Torvous)\
**Post date:** [April 8, 2022, 11:57am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-functions-1-test/95611/5 "2022-04-08T11:57:33Z")

</div>

Thank you for the additional resources!
