Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Oliver Sewell
Oliver Sewell
16,425 Points

I'm trying to add multiple li elements to an existing ul

Hi :) , I'm trying to append 3 separate li elements to a ul with the id list

  var ul = document.getElementById("list");
  var listItem1 = document.createElement("li");
  listItem1.appendChild(document.createTextNode('Name: ' + pokemon.name));
  var listItem2 = document.createElement("li");
  listItem2.appendChild(document.createTextNode('Level: ' + pokemon.level));
  var listItem3 = document.createElement("li");
  listItem3.appendChild(document.createTextNode('Health: 'pokemon.health));
  ul.appendChild(listItem1);
  ul.appendChild(listItem2);
  ul.appendChild(listItem3);

Thank you

1 Answer

I'm not entirely sure what you question is, but I noticed that on line 7 you are missing an addition operator. (a plus sign)

//instead of this
listItem3.appendChild(document.createTextNode('Health: 'pokemon.health));
//it should look like this
listItem3.appendChild(document.createTextNode('Health: ' + pokemon.health));
Oliver Sewell
Oliver Sewell
16,425 Points

Thank you for noticing that :) , im trying to append multiple li elements to an already existing ul so it looks like this <ul> <li> name </li> <li> level</li> <li> health</li> </ul>