Skip to content
Snippets Groups Projects
Commit 5fbb91fc authored by Eliott Collin's avatar Eliott Collin
Browse files

for on array to display pizza

parent 115e16b0
No related branches found
No related tags found
No related merge requests found
const name = "Regina", const data = ['Regina', 'Napolitaine', 'Spicy'];
url = `images/${name.toLowerCase()}.jpg`,
html = /*
`<article class="pizzaThumbnail"> const html = data.map(name => {
const url = `images/${name.toLowerCase()}.jpg`;
return `<article class="pizzaThumbnail">
<a href="${url}">
<img src="${url}" alt="${name}"/>
<section>${name}</section>
</a>
</article>`;
});
html.forEach(element => document.querySelector('.pageContent').innerHTML += element);
*/
/*
data.forEach(name => {
const url = `images/${name.toLowerCase()}.jpg`;
document.querySelector('.pageContent').innerHTML += `<article class="pizzaThumbnail">
<a href="${url}"> <a href="${url}">
<img src="${url}" alt="${name}"/> <img src="${url}" alt="${name}"/>
<section>${name}</section> <section>${name}</section>
</a> </a>
</article>`; </article>`;
});
*/
const tohtml = name => {
const url = `images/${name.toLowerCase()}.jpg`;
return `<article class="pizzaThumbnail">
<a href="${url}">
<img src="${url}" alt="${name}"/>
<section>${name}</section>
</a>
</article>`;
};
const reducer = (previous, current, index) => {
if(index === 1) previous = tohtml(previous);
return previous + tohtml(current);
};
const html = data.reduce(reducer);
console.log(html); console.log(html);
document.querySelector('.pageContent').innerHTML = html; document.querySelector('.pageContent').innerHTML = html;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment