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)
});
`s cannot contain `
– Sebastian Simon Oct 14 '21 at 01:42