I've been trying to figure this one out - if someone has some pointers I would appriciate it. Basically I got an object which has 3 properties, I need to check if one of those properties is true or false, and return based true/false. So far, made this code but as I understand it doesn't recognize object.properties..
const library = [
{
title: "Bill Gates",
author: "The Road Ahead",
isRead: true
},
{
title: "Steve Jobs",
author: "Walter Isaacson",
isRead: true
},
{
title: "Mockingjay: The Final Book of The Hunger Games",
author: "Suzanne Collins",
isRead: false
}
];
const showStatus = (arg) => {
let book = arg;
for(let i = 0;i < book.length; i++){
if(book.isRead === true){
console.log(`Already read ${book.title} by ${book.author}.`)
} else {
console.log(`You still need to read ${book.title} by ${book.author}`)
}
}
};
showStatus(library);
You take not really a book, like
const book = arg[i], // iterate arg
You could iterate the books and destructure a single entry into the parts and use this parts.
const library = [{
title: "Bill Gates",
author: "The Road Ahead",
isRead: true
},
{
title: "Steve Jobs",
author: "Walter Isaacson",
isRead: true
},
{
title: "Mockingjay: The Final Book of The Hunger Games",
author: "Suzanne Collins",
isRead: false
}
];
const showStatus = (books) => {
for (const { title, author, isRead } of books) {
if (isRead) {
console.log(`Already read ${title} by ${author}.`);
} else {
console.log(`You still need to read ${title} by ${author}`);
}
}
};
showStatus(library);