I'm pretty rubbish at JavaScript i was wondering if anyone could help.
I've mapped through some data from an API and displaying it to the page and i would like to also loop through the images in the images array so i have a different image for each card.
const images = ['https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature','https://placeimg.com/200/200/tech','https://placeimg.com/200/200/animals','https://placeimg.com/200/200/nature'];
function getPeople() {
const endpoint = "https://swapi.co/api/people/";
return fetch(endpoint)
.then(function(blob) {
return blob.json();
})
.then(function(data) {
return data.results;
});
}
getPeople().then(peopleObject => {
displayPerson(peopleObject)
});
function displayPerson(peopleObject) {
const people = peopleObject.map(person => {
return `
<div class="card">
<p> ${person.name} </p>
<p> ${person.height}cm </p>
<p> -- I WANT A IMAGE FROM IMAGE ARRAY HERE -- </p>
</div>
`
}).join('');
const cardContainer = document.createElement('div');
cardContainer.className += "card-container";
cardContainer.innerHTML = people;
document.body.appendChild(cardContainer);
}