NZMAI NZMAI - 4 months ago 15
Javascript Question

Fail to concatenate a string properly to create a link

I'm doing a project using Wikipedia API. I want ot create a link for every li. But fail to concatenate the right way.

This is my code

for (var j=0; j < wikiData.length; j++) {
var articleAuthor = wikiData[1][j];
var articleInfo = wikiData[2][j];
var linkAuthor = wikiData[3][j];
domCache.$wikiArticlesList.append('<li class="articleItem">'+ '<span>' + '<a href =' + '"linkAuthor">' + articleAuthor + '</a>' + '</span>' +'<span class="shortInfo">' + articleInfo +'</span>' + '</li>');
console.log(j + " " + articleAuthor);
console.log(j + " " + articleInfo);
console.log(j + " " + linkAuthor);
}


var linkAuthor = wikiData[3][j];

I want to concatenate linkAuthor variable to href(bolded). I know that problem is related to apostrophes. But my brain just stuck at it, i need someone to look at it with fresh eyes. Please help me.

Codepen project link

Answer
    domCache.$wikiArticlesList.append('<li class="articleItem">'+ '<span>' + '<a href =' + linkAuthor + '>' + articleAuthor + '</a>' + '</span>' +'<span class="shortInfo">' + articleInfo +'</span>' + '</li>'); 

Your linkAuthor was inside codes