Skip to content

Commit 015ea99

Browse files
committed
populate with content from JS3
1 parent 511a555 commit 015ea99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7051
-52
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
**/node_modules
3+
.DS_Store
4+
**/.DS_Store

.prettierrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"embeddedLanguageFormatting": "auto",
5+
"htmlWhitespaceSensitivity": "css",
6+
"insertPragma": false,
7+
"jsxBracketSameLine": false,
8+
"jsxSingleQuote": false,
9+
"printWidth": 80,
10+
"proseWrap": "preserve",
11+
"quoteProps": "as-needed",
12+
"requirePragma": false,
13+
"semi": true,
14+
"singleQuote": false,
15+
"tabWidth": 2,
16+
"trailingComma": "es5",
17+
"useTabs": false,
18+
"vueIndentScriptAndStyle": false
19+
}

Example-Image.jpeg

-910 KB
Binary file not shown.

HOW-TO-GET-HELP.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# How To Get Help
2+
3+
Learning to ask good questions is a key skill for a developer and you should practice this every week at CYF. You must spend a lot of time learning how to describe problems clearly and systematically:
4+
5+
https://curriculum.codeyourfuture.io/guides/asking-questions
6+
7+
Problem-solving is the real (marketable) skill of software developers. If you do not have questions to ask about your work, ask for some different work. Don't miss this opportunity to break down challenging problems with a large team of developers.
8+
9+
## Reporting Issues in Coursework
10+
11+
- Is there a problem with this coursework?
12+
- Have you noticed a bug?
13+
- Is there a typo or a mistake you can help clean up?
14+
15+
Open an issue or PR directly to the main repo. CYF Curriculum is an Open Source project developed on GitHub and you are invited to contribute. Read the Issue Template carefully.
16+
17+
https://github.com/CodeYourFuture/curriculum/

HOW_TO_REVIEW.md

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
<!--
2-
Do not edit this file.
3-
Make a change to the template and then pull changes
4-
Repo: https://github.com/CodeYourFuture/Module-Template
5-
-->
6-
71
# Everyone reviews code at CYF
82

3+
https://curriculum.codeyourfuture.io/guides/reviewing/
4+
95
Mentors and trainees all review code, and collaborate on improving code quality. We are all helping each other to talk, write, and think about code more clearly.
106

117
We are not reviewing code as if we were to merge this PR into production; we are opening a technical conversation for the purpose of insight and development.
@@ -53,14 +49,4 @@ Use these resources to inform your code review, get unstuck, and improve your un
5349

5450
## Guides
5551

56-
Here's a detailed checklist of the sorts of things we should check code for:
57-
58-
https://syllabus.codeyourfuture.io/guides/marking-guide
59-
60-
Here's a detailed style guide to help us all write clear, high quality code:
61-
62-
https://syllabus.codeyourfuture.io/guides/code-style-guide
63-
64-
Here's some help with giving good feedback during code review:
65-
66-
https://teachertraining.codeyourfuture.io/tasks/code-review
52+
https://curriculum.codeyourfuture.io/guides/reviewing/

contributing.md

-25
This file was deleted.

debugging/book-library/book.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { title, author, pages, read } from "./index.js";
2+
3+
const createBook = (title, author, pages, read) => {
4+
const book = {
5+
title,
6+
author,
7+
pages,
8+
read,
9+
};
10+
return book;
11+
};
12+
13+
export default createBook;

debugging/book-library/book.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import createBook from "./book";
2+
3+
describe("createBook", () => {
4+
test("should create a book object", () => {
5+
const title = "The Shining";
6+
const author = "Stephen King";
7+
const pages = 447;
8+
const read = true;
9+
const book = createBook(title, author, pages, read);
10+
11+
expect(book).toEqual({
12+
title: "The Shining",
13+
author: "Stephen King",
14+
pages: 447,
15+
read: true,
16+
});
17+
});
18+
});

debugging/book-library/books.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import createBook from "./book.js";
2+
const addBook = (books, newBook) => [...books, newBook];
3+
4+
// removeBook removes the book at the given index from the list of books
5+
const removeBook = (books, index) => [
6+
...books.slice(0, index),
7+
...books.slice(index + 1),
8+
];
9+
10+
export { createBook, addBook, removeBook };

debugging/book-library/books.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { createBook, addBook, removeBook } from "./books";
2+
3+
describe("addBook", () => {
4+
test("adds valid book to list", () => {
5+
const books = [];
6+
const newBook = createBook("ABC", "Author", 100, false);
7+
8+
const updatedBooks = addBook(books, newBook);
9+
10+
expect(updatedBooks).toEqual([newBook]);
11+
});
12+
13+
test("does not add invalid book missing fields", () => {
14+
const books = [];
15+
const invalidBook = createBook("ABC");
16+
17+
const updatedBooks = addBook(books, invalidBook);
18+
19+
expect(updatedBooks).toEqual([]);
20+
});
21+
});
22+
23+
describe("removeBook", () => {
24+
test("removes book at index", () => {
25+
const books = [
26+
createBook("A", "A", 1),
27+
createBook("B", "B", 2),
28+
createBook("C", "C", 3),
29+
];
30+
31+
const updatedBooks = removeBook(books, 1);
32+
33+
expect(updatedBooks).toEqual([
34+
createBook("A", "A", 1),
35+
createBook("C", "C", 3),
36+
]);
37+
});
38+
});
39+
});
40+
});

debugging/book-library/index.html

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>My Book Library</title>
5+
<link
6+
href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"
7+
rel="stylesheet"
8+
/>
9+
</head>
10+
11+
<body class="bg-gray-100 p-8 bg-gradient-to-r from-indigo-100">
12+
<h1 class="text-8xl font-bold mb-4">My Book Library</h1>
13+
14+
<form id="add-book" class="bg-white p-4 rounded-lg shadow-md max-w-2xl">
15+
<div class="mb-4">
16+
<label for="titleInput" class="block font-bold">Title:</label>
17+
<input
18+
id="titleInput"
19+
type="text"
20+
name="titleInput"
21+
class="border p-2 w-full"
22+
required
23+
/>
24+
</div>
25+
26+
<div class="mb-4">
27+
<label for="authorInput" class="block font-bold">Author:</label>
28+
<input
29+
id="authorInput"
30+
type="text"
31+
name="authorInput"
32+
class="border p-2 w-full"
33+
required
34+
/>
35+
</div>
36+
37+
<div class="mb-4">
38+
<label for="pagesInput" class="block font-bold">Pages:</label>
39+
<input
40+
id="pagesInput"
41+
type="number"
42+
name="pagesInput"
43+
class="border p-2 w-full"
44+
min="1"
45+
required
46+
/>
47+
</div>
48+
49+
<div class="flex items-center mb-4">
50+
<input id="readInput" name="readInput" type="checkbox" class="mr-2" />
51+
<label for="readInput">Read</label>
52+
</div>
53+
54+
<button
55+
type="submit"
56+
class="bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600"
57+
>
58+
Add Book
59+
</button>
60+
</form>
61+
62+
<table class="bg-white rounded-lg shadow-md mt-8 w-full">
63+
<thead>
64+
<tr>
65+
<th>Title</th>
66+
<th>Author</th>
67+
<th>Pages</th>
68+
<th>Read</th>
69+
<th>Remove</th>
70+
</tr>
71+
</thead>
72+
<template id="book-row" class="max-w-3xl">
73+
<tr>
74+
<td></td>
75+
<td></td>
76+
<td></td>
77+
<td></td>
78+
<td></td>
79+
</tr>
80+
</template>
81+
</table>
82+
83+
<script>
84+
const bookRowTemplate = document.getElementById('book-row');
85+
const bookTable = document.querySelector('table');
86+
87+
const addBookForm = document.getElementById('add-book');
88+
const titleInput = document.getElementById('titleInput');
89+
const authorInput = document.getElementById('authorInput');
90+
const pagesInput = document.getElementById('pagesInput');
91+
const readInput = document.getElementById('readInput');
92+
93+
const books = [];
94+
95+
function addBook(e) {
96+
e.preventDefault();
97+
98+
const book = {
99+
title: titleInput.value,
100+
</script>
101+
</body>
102+
</html>

debugging/book-library/index.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { addBook, removeBook, createBook, books } from "./books.js";
2+
3+
// UI logic
4+
5+
const addNewBook = (book) => {
6+
books = addBook(books, book);
7+
render();
8+
};
9+
10+
const removeSelectedBook = (index) => {
11+
books = removeBook(books, index);
12+
render();
13+
};
14+
15+
// get form elements
16+
const form = document.getElementById("add-book");
17+
const title = document.getElementById("titleInput");
18+
const author = document.getElementById("authorInput");
19+
const pages = document.getElementById("pagesInput");
20+
const read = document.getElementById("readInput");
21+
22+
// Render UI
23+
const render = () => {
24+
const template = document.getElementById("book-row");
25+
26+
const rows = books.map((book) => {
27+
const row = template.content.cloneNode(true);
28+
29+
row.querySelector("[title]").textContent = book.title;
30+
row.querySelector("[author]").textContent = book.author;
31+
row.querySelector("[pages]").textContent = book.pages;
32+
row.querySelector("[read]").textContent = book.read;
33+
34+
const removeBtn = row.querySelector("[remove]");
35+
36+
removeBtn.addEventListener("click", () => {
37+
removeSelectedBook(books.indexOf(book));
38+
});
39+
40+
bookList.appendChild(row);
41+
});
42+
};
43+
44+
// Event listeners
45+
form.addEventListener("submit", (e) => {
46+
e.preventDefault();
47+
const newBook = createBook(
48+
title.value,
49+
author.value,
50+
pages.value,
51+
read.checked
52+
);
53+
addNewBook(newBook);
54+
});
55+
56+
export { title, author, pages, read };

debugging/book-library/readme.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# My Book Library
2+
3+
## topics: debugging, DOM
4+
5+
My website should be able to:
6+
7+
- View a list of books that I've read
8+
- Add books to a list of books that I've read
9+
- Including title, author, number of pages and if I've read it
10+
- If any of the information is missing it shouldn't add the book and should show an alert
11+
- Remove books from my list
12+
13+
## Bugs to be fixed
14+
15+
1. Website loads but nothing works in my javascript
16+
2. Website loads but nothing happens
17+
3. Error in console when you try to add a book
18+
4. It uses the title name as the author name
19+
5. Delete button is broken
20+
6. When I add a book that I say I've read - it saves the wrong answer
21+
22+
I think there are other some other small bugs in my code...but I'm lazy so I can't fix them all.
23+
24+
I wish somebody would help me!

debugging/book-library/style.css

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.form-group {
2+
width: 400px;
3+
height: 300px;
4+
align-self: left;
5+
padding-left: 20px;
6+
}
7+
8+
.btn {
9+
display: block;
10+
}
11+
12+
.form-check-label {
13+
padding-left: 20px;
14+
margin: 5px 0px 5px 0px;
15+
}
16+
17+
button.btn-info {
18+
margin: 20px;
19+
}

0 commit comments

Comments
 (0)