From 459327f6f52d7c816a99428d77315347c38ccb27 Mon Sep 17 00:00:00 2001 From: Elmira Zangeneh Date: Thu, 15 Feb 2024 22:39:44 +0000 Subject: [PATCH 1/4] fixt delButton --- .vscode/settings.json | 3 +++ book-library/script.js | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json 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..b3669422 100644 --- a/book-library/script.js +++ b/book-library/script.js @@ -54,7 +54,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 @@ -90,11 +90,11 @@ function render() { //add delete button to every row and render again let delButton = document.createElement("button"); - delBut.id = i + 5; - cell5.appendChild(delBut); - delBut.className = "btn btn-warning"; - delBut.innerHTML = "Delete"; - delBut.addEventListener("clicks", function () { + delButton.id = i + 5; + cell5.appendChild(delButton); + delButton.className = "btn btn-warning"; + delButton.innerHTML = "Delete"; + delButton.addEventListener("clicks", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 4a8ace308a6435eaace11eb47b6ec1a30acd87f3 Mon Sep 17 00:00:00 2001 From: Elmira Zangeneh Date: Fri, 16 Feb 2024 14:44:02 +0000 Subject: [PATCH 2/4] change line 40-41 --- book-library/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book-library/script.js b/book-library/script.js index b3669422..bb74d508 100644 --- a/book-library/script.js +++ b/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(); } } From 3efbad2acb89e012a74c3bc7810b0d23d52da2e7 Mon Sep 17 00:00:00 2001 From: Elmira Zangeneh Date: Wed, 1 May 2024 16:34:09 +0100 Subject: [PATCH 3/4] fix delete button --- book-library/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book-library/script.js b/book-library/script.js index bb74d508..7120a4d6 100644 --- a/book-library/script.js +++ b/book-library/script.js @@ -94,7 +94,7 @@ function render() { cell5.appendChild(delButton); delButton.className = "btn btn-warning"; delButton.innerHTML = "Delete"; - delButton.addEventListener("clicks", function () { + delButton.addEventListener("click", function () { alert(`You've deleted title: ${myLibrary[i].title}`); myLibrary.splice(i, 1); render(); From 6eb8918975ca7c06de3db5dff65b8150172c1619 Mon Sep 17 00:00:00 2001 From: elmira zangeneh Date: Mon, 6 May 2024 23:59:55 +0100 Subject: [PATCH 4/4] make an API --- programmer-humour/index.html | 17 +++++++++++++++++ programmer-humour/index.js | 21 +++++++++++++++++++++ programmer-humour/readme.md | 26 +++++++++++++------------- programmer-humour/style.css | 5 +++++ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 programmer-humour/index.html create mode 100644 programmer-humour/index.js create mode 100644 programmer-humour/style.css diff --git a/programmer-humour/index.html b/programmer-humour/index.html new file mode 100644 index 00000000..219a3769 --- /dev/null +++ b/programmer-humour/index.html @@ -0,0 +1,17 @@ + + + + + + + + Programming humour + + + +
+
+ + + + \ No newline at end of file diff --git a/programmer-humour/index.js b/programmer-humour/index.js new file mode 100644 index 00000000..e9eb4d57 --- /dev/null +++ b/programmer-humour/index.js @@ -0,0 +1,21 @@ + +const getImages = async () => { + + return fetch('https://xkcd.now.sh/?comic=latest').then((data) => { + const response = data.json(); + return response; + }).catch(error => { + console.error('Fetch error:', error); + }); + +} + +function render() { + getImages().then((data) => { + const img = document.createElement('img'); + img.src = data.img; + document.querySelector('#container').appendChild(img); + + }) +} +window.onload = render; \ No newline at end of file diff --git a/programmer-humour/readme.md b/programmer-humour/readme.md index 2de3faaf..af25c351 100644 --- a/programmer-humour/readme.md +++ b/programmer-humour/readme.md @@ -1,13 +1,13 @@ -# Programmer humour - -Who knew programmers could be funny? - -Write an function that makes an API call to `https://xkcd.now.sh/?comic=latest` - -1. Create a `HTML`, `CSS` and `JavaScript` file to write your code in - -- Inside the same file write a program that gets the `json` using Fetch. -- A function should make an API call to the given endpoint: `https://xkcd.now.sh/?comic=latest` -- Log the received data to the console -- Render the `img` property into an `` tag in the DOM -- Incorporate error handling +# Programmer humour + +Who knew programmers could be funny? + +Write an function that makes an API call to `https://xkcd.now.sh/?comic=latest` + +1. Create a `HTML`, `CSS` and `JavaScript` file to write your code in + +- Inside the same file write a program that gets the `json` using Fetch. +- A function should make an API call to the given endpoint: `https://xkcd.now.sh/?comic=latest` +- Log the received data to the console +- Render the `img` property into an `` tag in the DOM +- Incorporate error handling diff --git a/programmer-humour/style.css b/programmer-humour/style.css new file mode 100644 index 00000000..0629fe24 --- /dev/null +++ b/programmer-humour/style.css @@ -0,0 +1,5 @@ +body { + display: flex; + justify-content: center; + align-items: center; +} \ No newline at end of file