07-Images
The Code
function displayResults(json) {
//CODE OMITTED
} else {
for(let i = 0; i < articles.length; i++) {
let article = document.createElement('article');
let heading = document.createElement('h2');
let link = document.createElement('a');
let img = document.createElement('img'); //1
let para = document.createElement('p');
let clearfix = document.createElement('div');
for(let j = 0; j < current.keywords.length; j++) {
let span = document.createElement('span');
span.textContent += current.keywords[j].value + ' ';
para.appendChild(span);
}
//2
if(current.multimedia.length > 0) {
//3
img.src = 'http://www.nytimes.com/' + current.multimedia[0].url;
//4
img.alt = current.headline.main;
}
clearfix.setAttribute('class','clearfix');
article.appendChild(heading);
heading.appendChild(link);
article.appendChild(img); //5
article.appendChild(para);
article.appendChild(clearfix);
section.appendChild(article);
}
}
};Analysis
Run the App
Last updated