From 2c02a40f9cc213e19a06085889d8981d97804929 Mon Sep 17 00:00:00 2001 From: Bakhat Begum Date: Mon, 12 Feb 2024 18:52:02 +0000 Subject: [PATCH 1/4] I added a line that was accidentally removed --- book-library/script.js | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/book-library/script.js b/book-library/script.js index dc14a775..1eac06f7 100644 --- a/book-library/script.js +++ b/book-library/script.js @@ -28,19 +28,24 @@ const check = document.getElementById("check"); //check the right input from forms and if its ok -> add the new book (object in array) //via Book function and start render function function submit() { + let titleValue = title.value; + let authorValue = author.value; + let pagesValue = pages.value; + let checkValue = check.checked; if ( - title.value == null || - title.value == "" || - pages.value == null || - pages.value == "" + titleValue == null || + authorValue == "" || + pagesValue == null || + checkValue == "" ) { alert("Please fill all fields!"); - return false; - } else { - let book = new Book(title.value, title.value, pages.value, check.checked); - library.push(book); - render(); } + + else { + let book = new Book(titleValue, authorValue, pagesValue, checkValue); + myLibrary.push(book); + render(); +} } function Book(title, author, pages, check) { @@ -49,39 +54,34 @@ function Book(title, author, pages, check) { this.pages = pages; this.check = check; } - 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 let length = myLibrary.length; for (let i = 0; i < length; i++) { - let row = table.insertRow(1); - let cell1 = row.insertCell(0); - let cell2 = row.insertCell(1); - let cell3 = row.insertCell(2); - let cell4 = row.insertCell(3); - let cell5 = row.insertCell(4); + const row = table.insertRow(1); + const cell1 = row.insertCell(0); + const cell2 = row.insertCell(1); + const cell3 = row.insertCell(2); + const cell4 = row.insertCell(3); + const cell5 = row.insertCell(4); cell1.innerHTML = myLibrary[i].title; cell2.innerHTML = myLibrary[i].author; cell3.innerHTML = myLibrary[i].pages; //add and wait for action for read/unread button - let changeBut = document.createElement("button"); + const changeBut = document.createElement("button"); changeBut.id = i; changeBut.className = "btn btn-success"; cell4.appendChild(changeBut); - let readStatus = ""; - if (myLibrary[i].check == false) { - readStatus = "Yes"; - } else { - readStatus = "No"; - } - changeBut.innerHTML = readStatus; + + const readStatus = myLibrary[i].check ? "Yes" : "No"; + changeBut.textContent = readStatus; changeBut.addEventListener("click", function () { myLibrary[i].check = !myLibrary[i].check; @@ -89,15 +89,17 @@ function render() { }); //add delete button to every row and render again - let delButton = document.createElement("button"); - delBut.id = i + 5; + const delBut = document.createElement("button"); + delBut.id = i; cell5.appendChild(delBut); delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delBut.innerText = "Delete"; + delBut.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); }); } -} +}; + + From 189c521f89dea614cf5f84b7c36f74270723fd53 Mon Sep 17 00:00:00 2001 From: Bakhat Begum Date: Wed, 14 Feb 2024 16:26:53 +0000 Subject: [PATCH 2/4] added html, script and style files, using fetch to a request rom API --- .vscode/settings.json | 3 +++ programmer-humour/index.html | 14 ++++++++++++++ programmer-humour/script.js | 31 +++++++++++++++++++++++++++++++ programmer-humour/style.css | 8 ++++++++ 4 files changed, 56 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 programmer-humour/index.html create mode 100644 programmer-humour/script.js create mode 100644 programmer-humour/style.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6f3a2913 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/programmer-humour/index.html b/programmer-humour/index.html new file mode 100644 index 00000000..02e86616 --- /dev/null +++ b/programmer-humour/index.html @@ -0,0 +1,14 @@ + + + + + + + + Programmer-humour + + +
+
+ + \ No newline at end of file diff --git a/programmer-humour/script.js b/programmer-humour/script.js new file mode 100644 index 00000000..d9b504dd --- /dev/null +++ b/programmer-humour/script.js @@ -0,0 +1,31 @@ + +function getImageFetch(){ + return fetch('https://xkcd.now.sh/?comic=latest').then((response) => { + if(!response.ok){ + return "Error"; + }else{ + return response.json(); + } + }); +} +getImageFetch(); + +let imageDiv = document.createElement('div'); +document.body.appendChild(imageDiv); + +function displayData(){ + getImageFetch().then((data) => { + if(!data){ + console.log("data can not found"); + } + const image = data.img; + + const createImage = document.createElement('img'); + createImage.src = image; + imageDiv.appendChild(createImage); + } ) +} +console.log(displayData()); + +window.onload = displayData; + diff --git a/programmer-humour/style.css b/programmer-humour/style.css new file mode 100644 index 00000000..241c53a1 --- /dev/null +++ b/programmer-humour/style.css @@ -0,0 +1,8 @@ +body{ + background-color: antiquewhite; + display: grid; + grid-template-columns: auto; + align-items: center; + justify-content: center; + margin-top: 90px; +} \ No newline at end of file From 3c46bfdfd748ef38e2a77d8c2a7178a299e49df9 Mon Sep 17 00:00:00 2001 From: Bakhat Begum Date: Wed, 14 Feb 2024 16:41:12 +0000 Subject: [PATCH 3/4] I deleted div tag from html file --- programmer-humour/index.html | 4 ++-- programmer-humour/script.js | 1 + programmer-humour/style.css | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/programmer-humour/index.html b/programmer-humour/index.html index 02e86616..102eecc4 100644 --- a/programmer-humour/index.html +++ b/programmer-humour/index.html @@ -8,7 +8,7 @@ Programmer-humour -
-
+ + \ No newline at end of file diff --git a/programmer-humour/script.js b/programmer-humour/script.js index d9b504dd..b364d566 100644 --- a/programmer-humour/script.js +++ b/programmer-humour/script.js @@ -14,6 +14,7 @@ let imageDiv = document.createElement('div'); document.body.appendChild(imageDiv); function displayData(){ + getImageFetch().then((data) => { if(!data){ console.log("data can not found"); diff --git a/programmer-humour/style.css b/programmer-humour/style.css index 241c53a1..d78f3f5e 100644 --- a/programmer-humour/style.css +++ b/programmer-humour/style.css @@ -1,4 +1,5 @@ body{ + background-color: antiquewhite; display: grid; grid-template-columns: auto; From f0eb9dfb455bdf6b61f4929a0834726c9e2e1213 Mon Sep 17 00:00:00 2001 From: Bakhat Begum Date: Wed, 14 Feb 2024 22:35:56 +0000 Subject: [PATCH 4/4] Deleted console.log --- programmer-humour/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programmer-humour/script.js b/programmer-humour/script.js index b364d566..6f5321e3 100644 --- a/programmer-humour/script.js +++ b/programmer-humour/script.js @@ -26,7 +26,7 @@ function displayData(){ imageDiv.appendChild(createImage); } ) } -console.log(displayData()); +displayData(); window.onload = displayData;