title: Customer List Challenge (TestDome)
body: <p>I'm trying to solve this challenge from TestDome and i need some help. I dont really understand how i must toggle the email and how to append the item to DOM...
  !!Please without Vanilla JS only!!</p>
  <p>Implement the showCustomers function so that it renders customers as list items. The first argument to the function, customers, is an array of objects with the name and email properties. The second argument to the function, targetList, is an unordered HTML list to which each customer should be added as a separate list item.</p>
  <p>The name and email properties should be added as two paragraphs inside the list item. At first, the email paragraph element should not be present in the DOM. The email paragraph element should be added to the DOM after the name is clicked, and it should be removed from the DOM when the name is clicked again.</p>
  <p>For example, the following code:</p>
  <pre><code>document.body.innerHTML = `
  &lt;div&gt;
    &lt;ul id=&quot;customers&quot;&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  `;
  let customers = [{name: &quot;John&quot;, email: &quot;john@example.com&quot;},
                   {name: &quot;Mary&quot;, email: &quot;mary@example.com&quot;}];
  showCustomers(customers, document.getElementById(&quot;customers&quot;));
  
  let customerParagraph = document.querySelectorAll(&quot;li &gt; p&quot;)[0];
  if(customerParagraph) {
    customerParagraph.click();
  }
  console.log(document.body.innerHTML);
  Should render:
  
  &lt;div&gt;
    &lt;ul id=&quot;customers&quot;&gt;
      &lt;li&gt;
        &lt;p&gt;John&lt;/p&gt;
        &lt;p&gt;john@example.com&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;Mary&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  <p>THIS IS MY CODE</p>
  <pre><code>function showCustomers(customers, targetList) {
   customers.forEach(item =&gt;{
    let res = `&lt;li&gt;
          &lt;p&gt; ${item.name}&lt;/p&gt;;
          &lt;p&gt; ${item.email}&lt;/p&gt;;
          &lt;/li&gt;;
    targetList.innerHTML = targetList.appendChild(res);
     
   })
  }
  </code></pre>
  <p><a href="https://www.testdome.com/questions/javascript/customer-list/49798?visibility=3&amp;skillId=2" rel="nofollow noreferrer">https://www.testdome.com/questions/javascript/customer-list/49798?visibility=3&amp;skillId=2</a></p>