diff --git a/debugging/book-library/index.html b/debugging/book-library/index.html index 23acfa71..2a4670f8 100644 --- a/debugging/book-library/index.html +++ b/debugging/book-library/index.html @@ -82,11 +82,11 @@

Library

+ diff --git a/debugging/book-library/readme.md b/debugging/book-library/readme.md index 3abe8c13..a8f07a0f 100644 --- a/debugging/book-library/readme.md +++ b/debugging/book-library/readme.md @@ -13,11 +13,15 @@ My website should be able to: ## Bugs to be fixed 1. Website loads but doesn't show any books +line 57 synthax error in render 2. Error in console when you try to add a book +line 41 the original code tried pushing to a wrong array name 3. It uses the title name as the author name +in line 40 title.value was repeated 4. Delete button is broken +line 92 inconsistent name deleteBut +line 97 typo 5. When I add a book that I say I've read - it saves the wrong answer +line 80 no should be first -I think there are other some other small bugs in my code...but I'm lazy so I can't fix them all. -I wish somebody would help me! diff --git a/debugging/book-library/script.js b/debugging/book-library/script.js index 75ce6c1d..21e72ccf 100644 --- a/debugging/book-library/script.js +++ b/debugging/book-library/script.js @@ -37,8 +37,8 @@ function submit() { alert("Please fill all fields!"); return false; } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); + let book = new Book(title.value, author.value, pages.value, check.checked); + myLibrary.push(book); render(); } } @@ -54,8 +54,8 @@ function render() { let table = document.getElementById("display"); let rowsNumber = table.rows.length; //delete old table - for (let n = rowsNumber - 1; n > 0; n-- { - table.deleteRow(n); +for (let n = rowsNumber - 1; n > 0; n--) { + table.deleteRow(n); } //insert updated row and cells let length = myLibrary.length; @@ -77,9 +77,9 @@ function render() { wasReadCell.appendChild(changeBut); let readStatus = ""; if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { readStatus = "No"; + } else { + readStatus = "Yes"; } changeBut.innerText = readStatus; @@ -89,12 +89,12 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); + let delBut = document.createElement("button"); delBut.id = i + 5; deleteCell.appendChild(delBut); delBut.className = "btn btn-warning"; delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); diff --git a/debugging/code-reading/readme.md b/debugging/code-reading/readme.md index 4090c14c..25dab569 100644 --- a/debugging/code-reading/readme.md +++ b/debugging/code-reading/readme.md @@ -16,7 +16,7 @@ Take a look at the following code: ``` Explain why line 5 and line 8 output different numbers. - +It happens because of the local and global scope being different, line 5 is 2 and line 8 is 1. ## Question 2 Take a look at the following code: @@ -34,6 +34,7 @@ console.log(y); ``` What will be the output of this code. Explain your answer in 50 words or less. +f1 does not return anything, so console.log is undefined, line 33 will be an error because of the local scope of y. ## Question 3 @@ -62,3 +63,8 @@ console.log(y); ``` What will be the output of this code. Explain your answer in 50 words or less. +f1(x) does not print, 9 because of the x being passeed by value +console.log(y) prints { x: 10 } because object is referenced and changed + +f1(x) doesn’t print, so console.log(x) will still prints 9 +Because objects are passed by reference, f2(y) changes the property and line 62 will print {x:10}. \ No newline at end of file