From 4a191c84d71454cdebd22f2c2eba6c70b45a1f4c Mon Sep 17 00:00:00 2001 From: Tatiana Grigorieva Date: Tue, 14 Jan 2020 20:44:45 -0500 Subject: [PATCH 1/5] first commit wth errors --- main.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/main.js b/main.js index 220d2e1..da17f41 100644 --- a/main.js +++ b/main.js @@ -1 +1,66 @@ // 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) { + for(i=0; i < books.length; i++) { + if(book.title === books[i].title) { + var checkedOut = books[i].getAttribute('checkedOut') + if(checkedOut === false) { + books[i].setAttribute('checkedOut', true); + } + else console.log('error in check out'); + } + } + } + + var returnBook = function(book) { + for(i=0; i < books.length; i++) { + if(book.title === books[i].title) { + var checkedOut = books[i].getAttribute('checkedOut'); + if(checkedOut === true) { + books[i].setAttribute('checkedOut', false); + } + else console.log('error in return'); + } + } + } + + return { + addBook: addBook, + checkOutBook: checkOutBook, + returnBook: returnBook + } + +} + +var Book = function(title, author){ + + var attributes = { + title: title, + author: author, + checkedOut: false + } + + var getAttribute = function(attribute) { + if (attributes[attribute]) { + return attributes[attribute]; + } + } + + var setAttribute = function(attribute, value) { + if (attributes[attribute]) { + attributes[attribute] = value; + } + } + + + return { + getAttribute: getAttribute, + setAttribute: setAttribute + } +} From b33adc3efa325d25f83e39de11b18ac9412cc90c Mon Sep 17 00:00:00 2001 From: Tatiana Grigorieva Date: Tue, 14 Jan 2020 20:49:47 -0500 Subject: [PATCH 2/5] errors fixed --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index da17f41..48b9fb6 100644 --- a/main.js +++ b/main.js @@ -47,13 +47,13 @@ var Book = function(title, author){ } var getAttribute = function(attribute) { - if (attributes[attribute]) { + if (attribute === 'checkedOut') { return attributes[attribute]; } } var setAttribute = function(attribute, value) { - if (attributes[attribute]) { + if (attribute === 'checkedOut') { attributes[attribute] = value; } } From 41728f51741d39b578465024172d849ab3999c15 Mon Sep 17 00:00:00 2001 From: Tatiana Grigorieva Date: Tue, 14 Jan 2020 21:05:27 -0500 Subject: [PATCH 3/5] one more error left to fix --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 48b9fb6..33bf52a 100644 --- a/main.js +++ b/main.js @@ -47,13 +47,13 @@ var Book = function(title, author){ } var getAttribute = function(attribute) { - if (attribute === 'checkedOut') { + if (attribute ) { return attributes[attribute]; } } var setAttribute = function(attribute, value) { - if (attribute === 'checkedOut') { + if (attribute ) { attributes[attribute] = value; } } From c4c537966748764f17b059dc73cf5e5818c3edb9 Mon Sep 17 00:00:00 2001 From: Tatiana Grigorieva Date: Tue, 14 Jan 2020 21:10:20 -0500 Subject: [PATCH 4/5] fixed --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 33bf52a..12a4085 100644 --- a/main.js +++ b/main.js @@ -53,7 +53,7 @@ var Book = function(title, author){ } var setAttribute = function(attribute, value) { - if (attribute ) { + if (attribute in attributes) { attributes[attribute] = value; } } From d6baac4770c2bfe9964482ffb3792eb16bbfc2fc Mon Sep 17 00:00:00 2001 From: Tatiana Grigorieva Date: Tue, 14 Jan 2020 21:19:12 -0500 Subject: [PATCH 5/5] minor changes added --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 12a4085..9a1b94d 100644 --- a/main.js +++ b/main.js @@ -10,7 +10,7 @@ var Library = function() { for(i=0; i < books.length; i++) { if(book.title === books[i].title) { var checkedOut = books[i].getAttribute('checkedOut') - if(checkedOut === false) { + if(!checkedOut) { books[i].setAttribute('checkedOut', true); } else console.log('error in check out'); @@ -22,7 +22,7 @@ var Library = function() { for(i=0; i < books.length; i++) { if(book.title === books[i].title) { var checkedOut = books[i].getAttribute('checkedOut'); - if(checkedOut === true) { + if(checkedOut) { books[i].setAttribute('checkedOut', false); } else console.log('error in return');