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
55 changes: 54 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
// write your code here to make the tests pass
const Library = function() {
let books = [];
let addBook = function(bookToAdd) {
books.push(bookToAdd)
}

let checkOutBook = function(bookCheckOut) {
let foundBook = books.some((book) => {
return book.getAttribute('title') == bookCheckOut.getAttribute('title')
})

if(foundBook) {
bookCheckOut.setAttribute('checkedOut', true)
};
}

let returnBook = function(bookToReturn) {
let foundBook = books.some((book) => {
return book.getAttribute('title') == bookToReturn.getAttribute('title')
})
if(foundBook) {
bookToReturn.setAttribute('checkedOut', false)
};
}

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

const Book = function(bookTitle, author) {
let attributes = {
checkedOut: false,
title: bookTitle,
author: author
}

let getAttribute = function(attributeName) {
return attributes[attributeName];
}

let setAttribute = function(attributeName, value){
//console.log(attributeName, value)
if (attributes[attributeName] != undefined) {
attributes[attributeName] = value;
}
}
return {
getAttribute: getAttribute,
setAttribute: setAttribute
}
}