I am a student just learning javascript.
I am working on a simple assignment to create an array, create a function that will add the array values to a list. Here is my code attached. In my javascript for statement, I added "document.write(places[i] + "
");", however this only show a list of the values. It doesn't show up in the ul section on my webpage.
Can you help correct this line of code.
Any help would be appreciated.
<body>
<header>
<h1>
Hands-on Project 3-3
</h1>
</header>
<article>
<h2>Scouting Locations</h2>
<div id="results">
<ul>
<li id="item1"></li>
<li id="item2"></li>
<li id="item3"></li>
<li id="item4"></li>
<li id="item5"></li>
</ul>
</div>
</article>
<script>
//array storing places to display
var places = ["Atlanta", "Nashville", "Dallas", "Los Angeles", "Miami"];
// function to generate list from array
function processPlaces() {
var liElements = document.getElementsByTagName('li');
for (var i = 0; i < 5; i++) {
// write each array element in places to its corresponding list item in liElements
document.write(places[i] + "<br />");
}
}
</script>
</body>
</html>