Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Can I use a functions argument as the prefix for a variable name? myFunction(id) { idvarName}

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!