Skip to content

ITP JAN 25 | Katarzyna Kazimierczuk | Data Flows | Debugging #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ <h1>Library</h1>
</thead>
<tbody>
<tr>
<!-- <td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td> -->
</tr>
</tbody>
</table>
Expand Down
8 changes: 6 additions & 2 deletions debugging/book-library/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
16 changes: 8 additions & 8 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion debugging/code-reading/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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}.