I’m working on a project that requires a list of books to be printed onto the page using an api url.
Code works wonders, but I’m struggling to limit the characters to 140 for the description as requested.
function renderItemHtml(item) {
return `<div class="book"><img src="${item.volumeInfo.imageLinks.thumbnail}" class="thumbnails"
alt="${item.singleTitle} by ${item.volumeInfo.authors[0]}" />
<div>
<h4>${item.volumeInfo.title}</h4>
<p><strong>${item.volumeInfo.authors}</strong></p>
<h8>${item.volumeInfo.description}</h8> <-------- what i need to limit
</div>
<br>
<h8>Pages: ${item.volumeInfo.pageCount}</h8>
</div>`
}
>Solution :
Just do this:
<h8>${item.volumeInfo.description.slice(0,140)}</h8>