Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3d30fb

Browse files
authored
Merge pull request HackYourFuture-CPH#165 from HackYourFuture-CPH/revert-164-revert-162-patch-4
Revert "Revert "Update homework.md""
2 parents 0391002 + 146d4f0 commit a3d30fb

File tree

1 file changed

+18
-145
lines changed

1 file changed

+18
-145
lines changed

javascript3/week3/homework.md

Lines changed: 18 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -4,154 +4,27 @@
44

55
Need to brush up on the homework setup process? Check [this](https://github.com/HackYourFuture-CPH/Git/blob/main/homework_hand_in.md) out before you get into some git confusion!
66

7-
## So why should i do this homework?
7+
For this weeks homework we will create a web applications that generates a screenshot of a website based on a url. We will combine two API's one to generate the screenshot and one to allow the user to save the screenshot.
88

9-
Using classes help with structuring code. It is one of many **design patterns**. Second it **connects everything** you have learned in js: functions, properties, methods, keys, arrays.
9+
API to generate screenshot: https://rapidapi.com/apishub/api/website-screenshot6/?utm_source=RapidAPI.com%2Fguides&utm_medium=DevRel&utm_campaign=DevRel
1010

11-
If you struggle to do this weeks homework there are a couple of things to do:
11+
API to save screenshot: https://crudcrud.com/
1212

13-
- Try watch this: https://www.youtube.com/watch?v=T-HGdc8L-7w&t=565s
14-
- Watch the class recording. If it for some reason is missing. Then watch these: [part 1](https://www.youtube.com/watch?v=KfEeUcT0PWY), [part 2](https://www.youtube.com/watch?v=jbnKWe92uv4), [part 3](https://www.youtube.com/watch?v=-lqbVK12lWM) [part 4](https://www.youtube.com/watch?v=E3Stsveg4rg)
15-
- Read up on [classes](https://javascript.info/class)
13+
Technical spesifications.
14+
1. User can enter a URL for a website and it will send back a screenshot of the website using the website-screenshot API
15+
2. User can hit a button to save the screenshot. It will then save the screenshot and the URL as a resource on crudcrud
16+
3. User can get a list of all screenshots he has saved
17+
4. User can delete a screenshot he has saved
1618

17-
## Lets make some art using classes
19+
Extra
20+
1. Create another resource called users which takes in an email and password. Create one user.
21+
2. Get back a list of users
22+
3. First show a login form
23+
4. If the email and password matches the one user we created we show the applications else we show an error message.
1824

19-
Lets create lots of circles in different sizes and colors on a webpage!
25+
Extra Extra
26+
1. Create another user
27+
2. When saving a screenshot also save the user email(or another unique identifer)
28+
3. Make sure we are only showing screenshots that the user that is logged in has uploaded
2029

21-
In HTML5 there is an elements called canvas. It **works just like a real canvas.** You can paint elements like lines, circles and much more to the canvas.
22-
23-
### Paint a circle to a canvas element
24-
25-
First add the `canvas` element to your html. Now draw a circle on the `canvas` using js. Google is your friend here :)
26-
27-
When you have added a normal circle, try filling it out so it has a color. Again google time!
28-
29-
### Class creation time!
30-
31-
Lets create a class called `Circle`. The circle should be used like this:
32-
33-
```js
34-
const c1 = new Circle(50, 50, 20, 0, 2 * Math.PI, "#000000");
35-
c1.draw();
36-
```
37-
38-
Where the constructor should look like this: `constructor(x, y, r, startAngle, endAngle, fillColor)`
39-
40-
The circle should have one method: `draw` that **draws the circle to the canvas**. That means that creating an instance of the circle class will not draw the circle. **Drawing the circle** first happens when we **call the draw method.**
41-
42-
Test if the new class works by creating a circle and drawing it to the canvas. Try some different radiuses, positions and fill colors.
43-
44-
### Now lets make art!
45-
46-
Every 100ms create a new circle instance and draw that to the canvas.
47-
48-
The circle should have random `x`, `y`, `radius` and `color`. For giving the `circle` a random color what should we do?? We should google off course!
49-
50-
What if we wanted the canvas to have the same width and height of the screen?
51-
52-
### Follow the mouse - optional
53-
54-
Instead of the circles just randomly appearing on the screen, make them appear around the cursor.
55-
56-
## Getting into promises
57-
58-
Lets use the github api to see **what repositories different users have**. You can use this url to get repositories for a specific github username, in this case the username `benna100`: `https://api.github.com/search/repositories?q=user:benna100`. Select 3 classmates github username that you want to show repositories for.
59-
60-
Fetch all the 3 classmates repositories **at the same time using Promise.all.** Remember the **all at once** exercise [here?](../week2/homework.md#visual-promise)
61-
62-
When you have the data for the different repositories, **render the fullname** of the repo, **url** of the repo, and **the owner** of the repo. See [github-repos](homework/github-repos.html) as an example of how the renderered repos should look. You are more than welcome to style it a bit nicer!
63-
64-
## Shopping cart using Classes
65-
66-
Let's get a bit more into creating classes!
67-
68-
```js
69-
class Product {
70-
constructor(name, price) {
71-
this.name = name;
72-
this.price = price;
73-
}
74-
}
75-
76-
class ShoppingCart {
77-
constructor() {
78-
this.products = [];
79-
}
80-
81-
addProduct(product) {
82-
// Implement functionality here
83-
}
84-
85-
removeProduct(product) {
86-
// Implement functionality here
87-
}
88-
89-
searchProduct(productName) {
90-
// Implement functionality here
91-
}
92-
93-
getTotal() {
94-
// Implement functionality here
95-
}
96-
97-
renderProducts() {
98-
// Implement functionality here
99-
}
100-
101-
getUser(user) {
102-
// Implement functionality here
103-
}
104-
}
105-
106-
const shoppingCart = new ShoppingCart();
107-
const flatscreen = new Product("flat-screen", 5000);
108-
shoppingCart.addProduct(flatscreen);
109-
```
110-
111-
So we have two classes. `Product` represents products. `ShoppingCart` represents a shopping cart.
112-
113-
### Part 1
114-
115-
Create the functionality for the `ShoppingCart` class.
116-
117-
- `addProduct` should add a product to the products array.
118-
- `removeProduct` should remove a product from the products array.
119-
- `getTotal` should get the total price of the products in the `shoppingcart`.
120-
- `renderProducts` should render the products to html. You decide what to show and how.
121-
- `searchProduct` should return an array of product that match the `productName` parameter
122-
- `getUser` should return a promise with the data from this api: https://jsonplaceholder.typicode.com/users/1 (replace '1' with correct user).
123-
124-
### Part 2
125-
126-
Try and create some products and call the `addProduct` and the `removeProduct` functions to see if they work.
127-
128-
Call the `getUser` function to get a user. When the user has been fetched. Render the products using the `renderProducts` method. Also render the username and the total price of the products in the `shoppingcart`.
129-
130-
_Optional and a little tricky!_ Create a **searchbar where a user can search for a product.** Matching product are shown as an autocomplete. **Clicking a product** in the autocomplete **opens a modal** with product information.
131-
132-
### Part 3
133-
134-
The `Product` class should get a method called `convertToCurrency`. The function should have `currency` as a parameter. Depending on the **provided currency return the correct price** for the product. Add 3 or more curriencies. Or use an api for getting the price dependent on a currency that `convertToCurrency` uses.
135-
136-
```js
137-
// Assuming dkr as default currency
138-
const plant = new Product("plant", 50);
139-
console.log(plant.convertToCurrency("dollars")); // 7.5
140-
```
141-
142-
### Part 4, optional
143-
144-
Be creative! Create some cool/weird/quirky functionality of either the `Product` class or the `ShoppingCart` class.
145-
146-
<br/>
147-
148-
## Hand in homework
149-
150-
Need to brush up on the homework hand-in process?<br/>
151-
Check [this resource](https://github.com/HackYourFuture-CPH/Git/blob/main/homework_hand_in.md) to remember how to hand in the homework correctly!
152-
153-
<br/>
154-
155-
## Feedback
156-
157-
We hope that you enjoyed the last module of Javascript. Please fill out the survey [here](https://forms.gle/YhbmqeC1EHaCDV5e7) to give feedback to the mentors and the staff.
30+
Keep in mind the API key for the website-screenshot and the uuid for crudcrud should be in a secret.js file which is not comitted to git

0 commit comments

Comments
 (0)