JSFiddle - React, Tailwind, and code Playground
by itsazzad
HTML
<div id="output">
<!--
Expected text inside this div:
Already read 'Bill Gates' by The Road Ahead.
Already read 'Steve Jobs' by Walter Isaacson.
You still need to read 'Mockingjay: The Final Book of The Hunger Games' by Suzanne Collins.
-->
</div>
JavaScript
var library = [{
title: 'Bill Gates',
author: 'The Road Ahead',
readingStatus: true
},
{
title: 'Steve Jobs',
author: 'Walter Isaacson',
readingStatus: true
},
{
title: 'Mockingjay: The Final Book of The Hunger Games',
author: 'Suzanne Collins',
readingStatus: false
}
];
// your code goes here
let output = [];
library.forEach(function(entry) {
let text = '';
if (entry.readingStatus) {
text += `Already read `;
} else {
text += `You still need to read `;
}
text += `'${entry.title}' by ${entry.author}.`;
output.push(text);
});
document.getElementById("output").innerText = output.join('\n');