fetch("https://apis.scrimba.com/jsonplaceholder/posts") .then(res => res.json()) .then(data => { const postsArr = data.slice(0, 5) let html = "" for (let post of postsArr) { html += ` <h3>${post.title}</h3> <p>${post.body}</p> <hr /> ` } document.getElementById("blog-list").innerHTML = html })
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter