Skip to content
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

WM4 | FATIMA SAFANA | Module-Data-Flows | Book library #145

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title> </title>
<title>Book Library </title>
<meta
charset="utf-8"
name="viewport"
Expand Down Expand Up @@ -31,15 +31,15 @@ <h1>Library</h1>
<div class="form-group">
<label for="title">Title:</label>
<input
type="title"
type="text"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="author"
type="text"
class="form-control"
id="author"
name="author"
Expand All @@ -58,7 +58,7 @@ <h1>Library</h1>
type="checkbox"
class="form-check-input"
id="check"
value=""
value="true"
/>Read
</label>
<input
Expand Down Expand Up @@ -91,6 +91,6 @@ <h1>Library</h1>
</tbody>
</table>

<script src="script.js"></script>
<script defer src="script.js"></script>
</body>
</html>
29 changes: 19 additions & 10 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let myLibrary = [];

window.addEventListener("load", function (e) {
populateStorage();
console.log(myLibrary);
render();
});

Expand All @@ -16,7 +17,7 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
//render();
}
}

Expand All @@ -29,6 +30,8 @@ const check = document.getElementById("check");
//via Book function and start render function
function submit() {
if (
author.value == null ||
author.value == "" ||
title.value == null ||
title.value == "" ||
pages.value == null ||
Expand All @@ -37,9 +40,13 @@ 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();
title.value = "";
author.value = "";
pages.value = "";
check.checked = false;
}
}

Expand All @@ -53,8 +60,9 @@ function Book(title, author, pages, check) {
function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
console.log(rowsNumber);
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n-- ){
Fatimasfn marked this conversation as resolved.
Show resolved Hide resolved
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -77,9 +85,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,14 +97,15 @@ function render() {
});

//add delete button to every row and render again
let delButton = document.createElement("button");
delBut.id = i + 5;
let delBut = document.createElement("button");
// delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
delBut.addEventListener("click", function () {
const deletedTitle = myLibrary[i].title;
myLibrary.splice(i, 1);
alert(`You've deleted title: ${deletedTitle}`);
render();
});
}
Expand Down
32 changes: 32 additions & 0 deletions fetch/programmer-humour/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1> programmer humor </h1>
<img id="humor"/>


</body>
<script>
async function makeApiCall(){
const url = "https://xkcd.now.sh/?comic=latest"

try {
const response = await fetch(url);
if (response.ok) {
const data = await response.json()
console.log(data)
const img = document.getElementById("humor")
img.src = data.img
}
} catch (error) {
console.log("error fetching data", error)
}
}
makeApiCall()
</script>
</html>