Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit 457dc4e

Browse files
committed
Add Homework
1 parent 2144f2e commit 457dc4e

File tree

38 files changed

+1112
-1
lines changed

38 files changed

+1112
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# JavaScript-Core-3-Homework
1+
# JavaScript Core 3 Homework
2+
3+
Homework for our third JavaScript module at CodeYourFuture
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Using the Debugger
2+
3+
The Chrome Debugger is a key tool you can use to find bugs in your code.
4+
5+
You should complete this online tutorial to get some experience using it.
6+
7+
https://developers.google.com/web/tools/chrome-devtools/javascript
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Tasks
2+
3+
## 1. Install ESLint
4+
5+
Using ESLint can make debugging a lot easier. If you haven't already you should install it now.
6+
7+
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
8+
9+
## 2. Thinking like a Programmer
10+
11+
During these past weeks you have gotten a taste of what programming is: the various concepts, what it looks like in code and the way it's used. However, having written some code doesn't make you a programmer. Thinking like a programmer makes you into a programmer. But what does that mean, 'thinking like a programmer'?
12+
13+
Thinking like a programmer is very similar to thinking like a construction worker:
14+
15+
You have to build something and it's up to you to know all the necessary tools and techniques to make that happen, and
16+
You have to solve every problem that comes up along the way (such as things that go wrong, knowing how to choose the right tools for the job and striving to achieve the right goal)
17+
The second skill, problem solving, is the most important one. If you get good at that, you'll automatically get good at the first.
18+
19+
Take a look at the following resources to learn more about problem solving as applied to programming:
20+
21+
- [How to THINK like a programmer](https://www.youtube.com/watch?v=NNazO2tMHno)
22+
- [Lessons in problem solving](https://www.freecodecamp.org/news/how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2/)
23+
- [Computational thinking](https://www.youtube.com/watch?v=qbnTZCj0ugI)
24+
25+
After you've watched these videos I'd like you to answer these questions
26+
27+
## 1. What do you think the most important quality for a programmer is?
28+
29+
<!-- Write your answer here -->
30+
31+
## 2. When trying to solve a challenge, what should you do first?
32+
33+
<!-- Write your answer here -->
34+
35+
## 3. What should you do if you get stuck?
36+
37+
<!-- Write your answer here -->
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title> </title>
5+
<meta
6+
charset="utf-8"
7+
name="viewport"
8+
content="width=device-width, initial-scale=1.0"
9+
/>
10+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
12+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
13+
<link
14+
rel="stylesheet"
15+
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
16+
/>
17+
<link rel="stylesheet" type="text/css" href="style.css" />
18+
</head>
19+
20+
<body>
21+
<div class="jumbotron text-center">
22+
<h1>Library</h1>
23+
<p>Add books to your virtual library</p>
24+
</div>
25+
26+
<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
27+
Add new book
28+
</button>
29+
30+
<div id="demo" class="collapse">
31+
<div class="form-group">
32+
<label for="title">Title:</label>
33+
<input
34+
type="title"
35+
class="form-control"
36+
id="title"
37+
name="title"
38+
required
39+
/>
40+
<label for="author">Author: </label>
41+
<input
42+
type="author"
43+
class="form-control"
44+
id="author"
45+
name="author"
46+
required
47+
/>
48+
<label for="pages">Pages:</label>
49+
<input
50+
type="number"
51+
class="form-control"
52+
id="pages"
53+
name="pages"
54+
required
55+
/>
56+
<label class="form-check-label">
57+
<input
58+
type="checkbox"
59+
class="form-check-input"
60+
id="check"
61+
value=""
62+
/>Read
63+
</label>
64+
<input
65+
type="submit"
66+
value="Submit"
67+
class="btn btn-primary"
68+
onclick="submit();"
69+
/>
70+
</div>
71+
</div>
72+
73+
<table class="table" id="display">
74+
<thead class="thead-dark">
75+
<tr>
76+
<th>Title</th>
77+
<th>Author</th>
78+
<th>Number of Pages</th>
79+
<th>Read</th>
80+
<th></th>
81+
</tr>
82+
</thead>
83+
<tbody>
84+
<tr>
85+
<td></td>
86+
<td></td>
87+
<td></td>
88+
<td></td>
89+
<td></td>
90+
</tr>
91+
</tbody>
92+
</table>
93+
94+
<script src="script.js"></script>
95+
</body>
96+
</html>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
let myLibrary = [];
2+
3+
window.addEventListener("load", function (e) {
4+
populateStorage();
5+
render();
6+
});
7+
8+
function populateStorage() {
9+
if (myLibrary.length == 0) {
10+
let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true);
11+
let book2 = new Book(
12+
"The Old Man and the Sea",
13+
"Ernest Hemingway",
14+
"127",
15+
true
16+
);
17+
myLibrary.push(book1);
18+
myLibrary.push(book2);
19+
render();
20+
}
21+
}
22+
23+
const title = document.getElementById("title");
24+
const author = document.getElementById("author");
25+
const pages = document.getElementById("pages");
26+
const check = document.getElementById("check");
27+
28+
//check the right input from forms and if its ok -> add the new book (object in array)
29+
//via Book function and start render function
30+
function submit() {
31+
if (
32+
title.value == null ||
33+
title.value == "" ||
34+
pages.value == null ||
35+
pages.value == ""
36+
) {
37+
alert("Please fill all fields!");
38+
return false;
39+
} else {
40+
let book = new Book(title.value, title.value, pages.value, check.checked);
41+
library.push(book);
42+
render();
43+
}
44+
}
45+
46+
function Book(title, author, pages, check) {
47+
this.title = title;
48+
this.author = author;
49+
this.pages = pages;
50+
this.check = check;
51+
}
52+
53+
function render() {
54+
let table = document.getElementById("display");
55+
let rowsNumber = table.rows.length;
56+
//delete old table
57+
for (let n = rowsNumber - 1; n > 0; n-- {
58+
table.deleteRow(n);
59+
}
60+
//insert updated row and cells
61+
let length = myLibrary.length;
62+
for (let i = 0; i < length; i++) {
63+
let row = table.insertRow(1);
64+
let cell1 = row.insertCell(0);
65+
let cell2 = row.insertCell(1);
66+
let cell3 = row.insertCell(2);
67+
let cell4 = row.insertCell(3);
68+
let cell5 = row.insertCell(4);
69+
cell1.innerHTML = myLibrary[i].title;
70+
cell2.innerHTML = myLibrary[i].author;
71+
cell3.innerHTML = myLibrary[i].pages;
72+
73+
//add and wait for action for read/unread button
74+
let changeBut = document.createElement("button");
75+
changeBut.id = i;
76+
changeBut.className = "btn btn-success";
77+
cell4.appendChild(changeBut);
78+
let readStatus = "";
79+
if (myLibrary[i].check == false) {
80+
readStatus = "Yes";
81+
} else {
82+
readStatus = "No";
83+
}
84+
changeBut.innerHTML = readStatus;
85+
86+
changeBut.addEventListener("click", function () {
87+
myLibrary[i].check = !myLibrary[i].check;
88+
render();
89+
});
90+
91+
//add delete button to every row and render again
92+
let delButton = document.createElement("button");
93+
delBut.id = i + 5;
94+
cell5.appendChild(delBut);
95+
delBut.className = "btn btn-warning";
96+
delBut.innerHTML = "Delete";
97+
delBut.addEventListener("clicks", function () {
98+
alert(`You've deleted title: ${myLibrary[i].title}`);
99+
myLibrary.splice(i, 1);
100+
render();
101+
});
102+
}
103+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
.form-group{
3+
width:400px;
4+
height:300px;
5+
align-self:left;
6+
padding-left: 20px;
7+
}
8+
9+
.btn {
10+
display: block;
11+
}
12+
13+
.form-check-label {
14+
padding-left: 20px;
15+
margin: 5px 0px 5px 0px;
16+
}
17+
18+
button.btn-info {
19+
margin: 20px;
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# My Book Library
2+
3+
My website should be able to:
4+
5+
- View a list of books that I've read
6+
- Add books to a list of books that I've read
7+
- Including title, author, number of pages and if I've read it
8+
- If any of the information is missing it shouldn't add the book and should show an alert
9+
- Remove books from my list
10+
11+
## Bugs to be fixed
12+
13+
1. Website loads but nothing works in my javascript
14+
2. Website loads but nothing happens
15+
3. Error in console when you try to add a book
16+
4. It uses the title name as the author name.
17+
5. Delete button is broken
18+
6. When I add a book that I say I've read - it saves the wrong answer
19+
20+
I think there are other some other small bugs in my code...but I'm lazy so I can't fix them all.
21+
22+
I wish somebody would help me!
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Project - Part 1
2+
3+
In this weeks project we will be using the knowledge we learnt from JS1 & JS2 to build the first version of our website
4+
5+
## Project Details
6+
7+
All of the details for this project can be found [here](https://github.com/CodeYourFuture/syllabus/tree/london/js-core-3/tv-show-dom-project)
8+
9+
You should complete up to and including Level 300
10+
11+
## Project Setup
12+
13+
It is very important that you make sure you project is setup correctly.
14+
15+
You should follow all of the setup steps [here](https://github.com/CodeYourFuture/syllabus/blob/london/js-core-3/tv-show-dom-project/getting-started.md)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Practice the concepts
2+
3+
This week's concepts can be challenging, therefore let's get an easy introduction using some interactive exercises! Check the following resources out and start practicing.
4+
5+
You can ignore anything to do with `XMLHttpRequest`
6+
7+
- [FreeCodeCamp](https://www.freecodecamp.org/news/a-practical-es6-guide-on-how-to-perform-http-requests-using-the-fetch-api-594c3d91a547/)
8+
9+
## Code along
10+
11+
Now that you've learned about APIs and how to connect with them, let's apply it in the context of a complete application.
12+
13+
In the following application you'll be making an API call to an external, public API.
14+
15+
Enjoy!
16+
17+
- [Vanilla JS Numbers Facts App - AJAX & Fetch](https://www.youtube.com/watch?v=tUE2Nic21BA)
18+
19+
## Question
20+
21+
The following endpoint is publicly available from Github
22+
23+
GET https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/comments
24+
25+
1. What would you put in the following fields? `{owner}`, `{repo}`, `{pull_number}`?
26+
27+
<!-- Write your answer here -->
28+
29+
2. Describe in a sentence what this API endpoint returns when all of the fields are completed?
30+
31+
<!-- Write your answer here -->
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Use fetch to load a greeting from the API and display it
3+
in the HTML element with the id "greeting-text".
4+
5+
API: https://codeyourfuture.herokuapp.com/api/greetings
6+
Response: A greeting in a random language
7+
8+
To learn more about fetch, refer to the doc:
9+
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
10+
11+
12+
================
13+
Expected result
14+
================
15+
16+
Open index.html in your browser. Every time you refresh the page,
17+
a different greeting should be displayed in the box.
18+
*/
19+
20+
fetch('*** Write the API address here ***')
21+
.then(function(response) {
22+
return response.text();
23+
})
24+
.then(function(greeting) {
25+
// Write the code to display the greeting text here
26+
});

0 commit comments

Comments
 (0)