creating a function that outputs linked text with different links on a single line, mapping links onto text if link exists

  hyperlink, javascript, reactjs

Hi all I am writing a function that will take in a string of names, then for each name if it is in a list, it will take the text of the name and add a link to it, if it is not it will simply display the text. The aim is to have these all in a single line when displayed.

function founderslinked(foundernames,foundersqueryname){
  var foundernames=foundernames.split(", ");
   var founderslinkstring='';
  foundernames.map((foundername)=>{
    var foundernamelower=foundername.toLowerCase();
    var foundernamelower=foundernamelower.replace(/s+/g, '-');
    if(founderqueryname.indexOf(foundernamelower>=0)){
      var thelink=`${links.index}/about/contributors/${foundernamelower}`;
      var thelink="<a href="+thelink+">"+foundername+"</a>";
      var thelink.innerHTML=thelink;

      founderslinkstring=founderslinkstring+","+thelink.

    }else{
         founderslinkstring+=founderslinkstring+" "+foundername;



   }
 
    
  })
return{founderslinkstring
}
}

founder names will be a string of the format "John Doe, Matt Jones, Frank Smith", and founderqueryname will be an array of the form [‘john-doe’,’frank-smith].
The founderqueryname array is an array of the queries, of the people that have a personal page; if a query with their first and last name is in founderqueryname that means they have a personal page and it can be linked to.

I am essentially wanting to display all their names on a single line with this function. so I want to input the string of names and the array of queries. if there is a query with their name on it I want to add their name with a link to the single line we will display. if there is no query with their name I want to add only the text without a link to the line. using the above array and string, the function when called on the string and array

{founders linked(namesoffounders,queryoffounders);}

should display something like:

John Doe( text and link),Matt Jones(only text no link), Frank Smith(text and link)

"thelink" is essentially the pathway to the persons page if they have one and I am adding their name with a link to their page if they have a page. however this does not work. I am only getting the text as strings any ideas on what I am doing wrong?

Source: Ask Javascript Questions

LEAVE A COMMENT