title: How can pass an img url from the constructor to a function and then create/append the image?
body: <p>I have a Card class that takes a url as a parameter, along with several others. The createCard function creates a card based on the parameters. How can I create and append the image(s) within the card based on the url input?</p>
  
  <p>Update: Reworked the code and got the correct result. How can I refine this to be the most efficient?</p>
  
  <pre><code>&lt;section id="shootout" class="memory-game"&gt;
  &lt;/section&gt;
  </code></pre>
  
  
  
  <pre class="lang-js prettyprint-override"><code>const game = document.getElementById('shootout')
  
  class Card {
    constructor(name, imgUrl, health, ammo) {
      this.name = name
      this.health = health
      this.ammo = ammo
      this.imgUrl = imgUrl
    }
    createCard(imgUrl) {
      let card = document.createElement('div')
      card.className = this.name
      card.dataset.health = this.health
      card.dataset.ammo = this.ammo
      const addImages = () =&gt; {
        let frontFace = new Image()
        frontFace.src = this.imgUrl
        frontFace.className = 'front-face'
        let backFace = new Image()
        backFace.src = 'img/card-back.svg'
        backFace.className = 'back-face'
        card.append(backFace)
        card.append(frontFace)
      }
      addImages()
      game.appendChild(card)
    }
  }
  
  // Test Card Instance
  const testCard = new Card('ammunition', 'img/react.svg', 1, null).createCard()
  </code></pre>
  
  <p>Updated Code:</p>
  
  <pre><code>class Card {
    constructor(name, imgUrl, health, ammo) {
      this.name = name
      this.health = health
      this.ammo = ammo
      this.imgUrl = imgUrl
      this.addImages = (card) =&gt; {
        let frontFace = new Image()
        frontFace.src = this.imgUrl
        frontFace.className = 'front-face'
        let backFace = new Image()
        backFace.src = 'img/card-back.svg'
        backFace.className = 'back-face'
        card.append(backFace)
        card.append(frontFace)
      }
    }
    createCard(imgUrl) {
      let card = document.createElement('div')
      card.className = this.name
      card.dataset.health = this.health
      card.dataset.ammo = this.ammo
      this.addImages(card)
      game.appendChild(card)
    }
  }
  </code></pre>