Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error

Basically adding a forEach loop to spit out my array right now while practicing using DOM. I get the error in my console log. In my html I have the ul class "pokemon-list", and an empty li with the class "list-item".. What exactly did I do wrong here?

//IIFE function
let pokemonRepository = (function () {
  //List of pokemon Array
  let pokemonList = [
    {
     name: 'Bulbasaur ',
     height: 2.4,
     types: ['Grass ', 'Poison']
   },
    {
     name: ' Charmander ',
     height: 2,
     types: 'Fire'
   },
    {
     name: ' Squirtle ',
     height: 1.8,
     types: 'Water'
   }
  ];
//adds pokemon to the pokedex
  function add(pokemon) {
    pokemonList.push(pokemon);
  }
  function getAll() {
    return pokemonList
  }
  return {
    add: add,
    getAll: getAll
  }
})();
// for each function to write pokemon and its name
  pokemonRepository.getAll().forEach(function(pokemon){
  let listContainer = document.querySelector('.pokemon-list');
  let listItem = document.createElement('li');
  let button = document.createElement('button');
  button.innerText = pokemonRepository.name
  button.classList.add('poke-button');
  button.appendChild(listContainer);
  button.appendChild(listItem)
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From what I understand you are trying to make a list of buttons, but from your code that is not what is happening. You are trying to embed a list inside a button.

<ul class="pokemon-list">

</ul>

<script>
//IIFE function
let pokemonRepository = (function () {
  //List of pokemon Array
  let pokemonList = [
    {
     name: 'Bulbasaur ',
     height: 2.4,
     types: ['Grass ', 'Poison']
   },
    {
     name: ' Charmander ',
     height: 2,
     types: 'Fire'
   },
    {
     name: ' Squirtle ',
     height: 1.8,
     types: 'Water'
   }
  ];
//adds pokemon to the pokedex
  function add(pokemon) {
    pokemonList.push(pokemon);
  }
  function getAll() {
    return pokemonList
  }
  return {
    add: add,
    getAll: getAll
  }
})();
// for each function to write pokemon and its name
  pokemonRepository.getAll().forEach(function(pokemon){
  let listContainer = document.querySelector('.pokemon-list');
  let listItem = document.createElement('li');
  let button = document.createElement('button');
  button.innerText = pokemon.name;
  button.classList.add('poke-button');
  listItem.appendChild(button);
  listContainer.appendChild(listItem);
});

I spotted some few things.

  1. button.innerText = pokemonRepository.name should be pokemon.name
  2. You are appending listContainer and listItem to the button so change the followings.

button.appendChild(listContainer); button.appendChild(listItem)

to

listItem.appendChild(button); listContainer.appendChild(listItem);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!