Edit: what worked for me (as was suggested) was to use the arrays as arguments in the function call...
let navText = ['House', 'Food', 'Work'];
let navLinks = ['house.html', 'food.html', 'work.html'];
function navBuilder(id, textList, linkList) {
// Getting the element with the id
navList = document.getElementById(id);
// let openTag = document.innerHTL
// looping through the arrays and matching the text with the link
for (let i = 0; i < textList.length; i++) {
listItem = document.createElement('li');
// adds classes
listItem.className = id + '_list_item';
linkClass = id + "_list_link";
// put it all together
listItem.innerHTML += "<a href=\"" + linkList[i] + "\" class=\"" + linkClass + "\">" + textList[i] + "</a></li>";
navList.appendChild(listItem);
}
}
// Call the function here or include it in a script tag at the end of the html.
navBuilder("nav", navText, navLinks);
Thanks for the help!
let navText = ['House', 'Food', 'Work'];
let navLinks = ['house.html', 'food.html', 'work.html'];
function navBuilder(id, textList, linkList) {
// Getting the element with the id
navList = document.getElementById(id);
// let openTag = document.innerHTL
// looping through the arrays and matching the text with the link
for (let i = 0; i < textList.length; i++) {
listItem = document.createElement('li');
// adds classes
listItem.className = id + '_list_item';
linkClass = id + "_list_link";
// put it all together
listItem.innerHTML += "<a href=\"" + linkList[i] + "\" class=\"" + linkClass + "\">" + textList[i] + "</a></li>";
navList.appendChild(listItem);
}
}
// Call the function here or include it in a script tag at the end of the html.
navBuilder("nav", navText, navLinks);
It was just a slight modification to what I was doing to begin with. It was for sure a x and y problem