The Array .push method is not working for me!

I don’t know what is going on! Here’s my program:

var my_List = []

And that array goes into this funtion:

function addToTheList(thingToAdd) {
  var newListItem = document.createElement("li")
  newListItem.innerHTML = myList[myList.length - 1]

This is what shows up in the console

I don’t know what’s going on!
Full programming is at

What does the line that calls addToTheList() look like; you’ve not listed that here.

Hi @chancelorne! In the fiddle, you have this line:

addButton.addEventListener("click", addTheThing())

So you’re not binding addTheThing as a listener function, you’re immediately calling it and passing its return value (which is undefined); and when you are doing this, my_List has not been initialised yet. Also note the typo – sometimes you’re calling it my_List, sometimes myList.

Thanks! Now it works (but I have to figure out why it says[object HTMLInputElement] in the line when I put in ‘A Cat’. Well, thanks anyways!

because you print/stringify the input element instead of its value.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.