I have this html file in which I want to display an ordered list.the list comes from an array which is in a js file and every time I use "src" to connect the two documents I keep getting an error saying the arrays in the js file have been declared which they have not been. HTML code
<div id=fruit>
<h3>Displaying Fruits</h3>
<script src="js/list.js">
var list = document.createElement('ol');
fruits.forEach(function (element){
var li = document.createElement('li');
li.textContent = element;
list.appendChild(li);
});
var fruit = document.querySelector('#fruit');
fruit.appendChild(list);
</script>
</div>
JS code
const fruits = ['Apples', 'Oranges', 'Pears', 'Grapes', 'Pineapples', 'Mangos'];
error
Uncaught SyntaxError: Identifier 'fruits' has already been declared at VM13 list.js:1
list.js- also you should load up yourlist.jsas a script and then have a separate script tag for your html javascript