Skip to content
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
7 changes: 7 additions & 0 deletions challenges/unit-testing/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions challenges/unit-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"description": "",
"devDependencies": {
"jest": "^29.7.0"
},
"dependencies": {
"unit-testing": "file:"
}
}
24 changes: 13 additions & 11 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
}
}
}

const title = document.getElementById("title");
Expand All @@ -32,17 +31,20 @@ function submit() {
title.value == null ||
title.value == "" ||
pages.value == null ||
pages.value == ""
pages.value == "" ||
author.value == null ||
author.value == ""
) {
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();
}
}


function Book(title, author, pages, check) {
this.title = title;
this.author = author;
Expand All @@ -54,7 +56,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand Down Expand Up @@ -90,11 +92,11 @@ function render() {

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delButton.id = i + 5;// fixed the consistency of the naming
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
Loading