function Book(title, author, isbn, stock, cost) {
this.title = title;
this.author = author;
this.isbn = isbn;
this.stock = stock;
this.cost = cost;
this.summary = function () {
`${this.title} by ${this.author} (ISBN: ${this.isbn}) costs $ ${this.cost}`;
};
this.isAvailable = function () {
this.stock > 0
? `${this.title} is available`
: `${this.title} is not available at the moment`;
};
}
const product = new Book(
"The Design of Everyday Things",
"Don Norman",
"978 - 0 - 465 - 05571 - 5",
10,
17.99
);
console.log(product.summary());
console.log(product.isAvailable());
It has to print:
"The Design of Everyday Things by Don Norman (ISBN: 978 - 0 - 465 - 05571 - 5) costs $17.99"
"The Design of Everyday things is available"
returnto get a result returned by a normal function call.