From 5fdd0260d02220b9197111d64b62bdf0967fdd08 Mon Sep 17 00:00:00 2001 From: Pierre Lourens Date: Tue, 28 Apr 2020 22:21:03 -0400 Subject: [PATCH 1/3] Initial attempt --- main.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 220d2e1..8c7d3fc 100644 --- a/main.js +++ b/main.js @@ -1 +1,48 @@ -// 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); + } + }; + + var returnBook = function(book) { + if (books.includes(book)) { + book.setAttribute("checkedOut", false); + } + }; + + return { + addBook, + checkOutBook, + returnBook, + }; +}; + +var Book = function(title, author) { + var attributes = { + title, + author, + checkedOut: false, + }; + + var getAttribute = function(attribute) { + return attributes[attribute]; + }; + + var setAttribute = function(attribute, status) { + if (attribute in attributes) { + attributes[attribute] = status; + } + }; + + return { + getAttribute, + setAttribute, + }; +}; From c9b3f5b69c0ffa5ac846f82f1ee6ba0a0588d840 Mon Sep 17 00:00:00 2001 From: Pierre Lourens Date: Tue, 28 Apr 2020 22:23:44 -0400 Subject: [PATCH 2/3] Adds error messages if not in library --- main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.js b/main.js index 8c7d3fc..fe1c80a 100644 --- a/main.js +++ b/main.js @@ -8,12 +8,16 @@ var Library = function() { var checkOutBook = function(book) { if (books.includes(book)) { book.setAttribute("checkedOut", true); + } else { + console.log("We don't stock that book."); } }; var returnBook = function(book) { if (books.includes(book)) { book.setAttribute("checkedOut", false); + } else { + console.log("We don't stock that book."); } }; From 924c4165a9d6ecc7fa07044b254575e8e2099cb8 Mon Sep 17 00:00:00 2001 From: Pierre Lourens Date: Tue, 28 Apr 2020 22:29:00 -0400 Subject: [PATCH 3/3] Beautifies; changes status variable name to attributeInfo for clarity --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index fe1c80a..73ae7b2 100644 --- a/main.js +++ b/main.js @@ -39,9 +39,9 @@ var Book = function(title, author) { return attributes[attribute]; }; - var setAttribute = function(attribute, status) { + var setAttribute = function(attribute, attributeInfo) { if (attribute in attributes) { - attributes[attribute] = status; + attributes[attribute] = attributeInfo; } };