Currently, I am facing a challenge with displaying 100 posts using the Fetch API on one single page. I am looking for a way to create separate pages where each page would showcase only 10 posts.
Below is my existing JavaScript code:
fetch('https://jsonplaceholder.typicode.com/posts')
.then((res)=>res.json())
.then((data)=>{
let output = '<h2 class="posts"></h2>';
let i=0;
data.forEach(function(thePost){
output += `
<div style="background-color: gray;margin-
right:60px;width:300px;height:350px;border-radius: 30px;display:
inline-block;overflow: hidden;" class="post" id=item${i}>
<h3 style="padding:10px;color:white;">${thePost.title}</h3>
<p style="padding:10px;color:white;">${thePost.body}</p>
</div>
`;
i++;
//if (i==3){`<br> <br>`}
});
document.getElementById('posts').innerHTML=output;
});
You can view how the div posts appear here.