title: How to do to be able to filter a value in the array and thus add it to the "cart" and then add it to a variable and be able to show the result
body: <p>In this code I have an Array made up of different pets.</p>
  <p>1.- I want to make a shopping cart with the pet that the user selects and I don't understand how to filter the value by calling &quot;price&quot; in the array and thus add it to the cart.</p>
  <p>In the showListWithData() function it is intended that a list with all the pets be displayed and that the user can choose which one to buy by entering the name. Once having the &quot;name&quot; value, I don't know how to filter the price value to add it to a variable.</p>
  <p>2.- I also used the JSON.Stringify method but I don't know if I did it correctly... I understand something of what I'm doing but maybe the problem is that I have to implement the DOM modification and interact with some elements...</p>
  <pre><code>class Pet {
      constructor(id, name, breed, age, price) {
          this.id = id;
          this.name = name;
          this.breed = breed;
          this.age = parseInt(age);
          this.price = parseInt(price);
      }
  }
  
  let pet = [];
  pet.push(new Pet(1, &quot;bobby&quot;, &quot;bulldog&quot;, 3, 11000));
  pet.push(new Pet(2, &quot;mintus&quot;, &quot;golden&quot;, 2, 9000));
  pet.push(new Pet(3, &quot;spencer&quot;, &quot;labrador&quot;, 6, 13000,));
  pet.push(new Pet(4, &quot;toto&quot;, &quot;poodle&quot;, 4, 6000));
  pet.push(new Pet(5, &quot;keroto&quot;, &quot;shepherd&quot;, 7, 16000));
  
  function newPet() {
      this.id = prompt(&quot;enter identification number&quot;)
      this.name = prompt(&quot;pet's name&quot;);
      this.breed = prompt(&quot;enter breed&quot;);
      this.weight = parseInt(prompt(&quot;enter weight&quot;));
      this.price = parseInt(prompt(&quot;enter price&quot;));
  
      pets.push(new Pet(this.id, this.name, this.breed, this.weight, this.price))
      console.log(pets);
  }
  
  function showListWithData() {
      pets.forEach(pet =&gt; console.log(
          `number: ${pet.id} name: ${pet.name} breed: ${pet.breed} age: ${pet.age} years price: $${pet.price} `));
      let choice = prompt(&quot;choose which pet you want to buy&quot;);
      if (choice = pets.find(pet =&gt; pet.nombre === choice)) {
          console.log(`thanks for buying  ${JSON.stringify(choice)}`);
         let cart = pet.price;
          console.log(`cart total is: $ ${cart}`);
      } else {
          alert(&quot;that name is not on the list&quot;);
      }
  }
  
  function addPet() {
      newEntry = prompt(&quot;want to add a new pet? type 'yes' to add it&quot;)
      if (newEntry == &quot;yes&quot;) {
          newPet();
          console.log(this.name + &quot;has been added to the list&quot;);
      } else {
          alert(&quot;no pets entered&quot;);
      }
  }
  
  function quantityPets() {
      console.log(&quot;there are &quot; + pets.length + &quot; pets on the list&quot;)
  }
  
  function findPet() {
      let search = prompt(&quot;write the name of the pet to search&quot;);
      const result = pets.find((pet) =&gt; pet.name == search);
      console.log (JSON.stringify(result));
  }
  
  function findBreed() {
      let searchForBreed = prompt(&quot;enter breed&quot;);
      const result2 = pets.filter((pet) =&gt; pet.breed == searchForBreed);
      console.log(JSON.stringify(result2));
  }
  
  
  
  
  
  
  &lt;!DOCTYPE html&gt;
    &lt;html lang=&quot;en&quot;&gt;
  
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;title&gt;Demo&lt;/title&gt;
      &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;
        integrity=&quot;sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx&quot; crossorigin=&quot;anonymous&quot;&gt;
    &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h2&gt;Pet list management&lt;/h2&gt;
  
  &lt;button onclick=&quot;addPet()&quot;&gt;Enter new Pet&lt;/button&gt;&lt;br&gt;
  &lt;button onclick=&quot;quantityPets()&quot;&gt;Show number of pets&lt;/button&gt;&lt;br&gt;
  &lt;button onclick=&quot;findPet()&quot;&gt;Search Pet by name&lt;/button&gt;&lt;br&gt;
  &lt;button onclick=&quot;findBreed()&quot;&gt;Show Pet by breed&lt;/button&gt;&lt;br&gt;
  &lt;button onclick=&quot;showListWithData()&quot;&gt;Show List With Data&lt;/button&gt;&lt;br&gt;
  
    &lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>