Inserting razor syntax inside javascript function

Clash Royale CLAN TAG#URR8PPPInserting razor syntax inside javascript function
Im trying to loop over a collection of data inside a div like this but received and error that says Unterminated string literal. Strings that start with a quotation mark (") must be terminated before the end of the line. How can i solve this?
<a href="@(eventItem.Url)" class="media-box__cover">
@if (listingImageUrl == "") {
if (currentCount % 2 == 0) {
<div class="media-box__cover-image" style="background-color: #ffd205;"></div>
}else {
<div class="media-box__cover-image" style="background-color: #0d9430;"></div>
}
} else {
<div class="media-box__cover-image" style="background-image: url('@(listingImageUrl)');"></div>
}
</a>
into this,
for (i = 0; i < json["data"].length ; i++) {
if(typeof(json["data"][i]) == 'object' && json["data"][i] != null){
htmlRetStr = "<div class='block'><div class='media-boxes'>";
htmlRetStr += "<div class='media-box'>";
htmlRetStr += "<a href=""+ json["data"][i]["eventUrl"] +"" class='media-box__cover'>";
htmlRetStr += "@if (json["data"][i]["eventUrl"] == '') { "; //error here
htmlRetStr += "if (currentCount % 2 == 0) {";
htmlRetStr += "<div class='media-box__cover-image' style='background-color: #ffd205;'></div>";
htmlRetStr += "}else{";
htmlRetStr += "<div class='media-box__cover-image' style='background-color: #0d9430;'></div> }";
htmlRetStr += " } else {";
htmlRetStr += "<div class='media-box__cover-image' style='background-image: url(""+ json["data"][i]["listingImage"] +"");'></div>} </a>";
htmlRetStr += "<div class='media-box__main'><div class='media-box__main-inner'><div class='media-box__header'>";
htmlRetStr += "<h3 class='media-box__heading'><a href=""+ json["data"][i]["eventUrl"] +"" class='media-box__heading-link'>" + json["data"][i]["heading"] + "</a></h3>";
htmlRetStr += "<div class='media-box__meta'>Posted on: " + json["data"][i]["articleDate"] +" "+ json["data"][i]["articleMonth"] +" "+ json["data"][i]["articleYear"] + "</div></div>";
htmlRetStr += "<p>"+ json["data"][i]["subHeading"] +"…</p>";
htmlRetStr += "</div></div></div></div></div>";
$("#news").append(htmlRetStr);
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.