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/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(); }); } -} +}; + + diff --git a/programmer-humour/index.html b/programmer-humour/index.html new file mode 100644 index 00000000..102eecc4 --- /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..6f5321e3 --- /dev/null +++ b/programmer-humour/script.js @@ -0,0 +1,32 @@ + +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); + } ) +} +displayData(); + +window.onload = displayData; + diff --git a/programmer-humour/style.css b/programmer-humour/style.css new file mode 100644 index 00000000..d78f3f5e --- /dev/null +++ b/programmer-humour/style.css @@ -0,0 +1,9 @@ +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