Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
// write your code here to make the tests pass
var Library = function() {
var books = [];

var addBook = function(book) {
books.push(book);
};

var checkOutBook = function(book) {
if(books.includes(book)) {
book.setAttribute("checkedOut", true);
} else {
console.log("Book cannot be checked out as it is already checked out");
}
};

var returnBook = function(book) {
if(books.includes(book)) {
book.setAttribute("checkedOut", false);
}
};

return {
addBook: addBook,
checkOutBook: checkOutBook,
returnBook: returnBook
};
};

var Book = function(title, author) {

var attributes = {
title: title,
author: author,
checkedOut: false
};

var getAttribute = function(attribute) {
return attributes[attribute];
};

var setAttribute = function(attribute, value) {
if(Object.keys(attributes).includes(attribute)) {
attributes[attribute] = value;
}
};

return {
getAttribute: getAttribute,
setAttribute: setAttribute
};
};