Skip to content

Commit 7ac8510

Browse files
committed
moved homework for week 2 to week 3 + some cosmetics
1 parent 623e175 commit 7ac8510

3 files changed

Lines changed: 90 additions & 77 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
> Please help us improve and share your feedback! If you find better tutorials or links, please share them by opening a Pull Request.
21

3-
# Hack Your JavaScript
2+
# Hack Your JavaScript — Class 10
43
Here you can find course content and homework for the JavaScript 1,2 and 3 modules
54

65
|Week|Topic|Read|Homework|
76
|----|-----|----|--------|
8-
|0.|Preparation for your first JavaScript session|[Reading Week 0](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week0)|-|
9-
|1.|• Intro JavaScript (What is it, where can you<br> use it for)<br>• Basic Data types [Strings, Numbers, Arrays]<br>• Variables<br>• Operators<br>• Conditions <br>• Naming conventions| [CLI Reading Week 1](https://github.com/HackYourFuture/CommandLine/blob/MandT/Lecture-1.md)| [Homework Week 1](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week1/MAKEME.md)|
7+
|0.|Preparation for your first JavaScript session|[Pre-reading](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week0)|-|
8+
|1.|• Intro JavaScript (What is it, where can you use it for)<br>• Basic Data types [Strings, Numbers, Arrays]<br>• Variables<br>• Operators<br>• Conditions <br>• Naming conventions| [CLI Reading Week 1](https://github.com/HackYourFuture/CommandLine/blob/MandT/Lecture-1.md)| [Homework Week 1](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week1/MAKEME.md)|
109
|2.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :heart: <br> • Loops (for/while)<br>• Functions <br>• Closures <br>• Scope |[Reading Week 2](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week2)|[JS](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week2/MAKEME.md) + [CLI Homework Week 2](https://github.com/HackYourFuture/CommandLine/blob/MandT/HomeWork.md)|
1110
|3.|[CLI](https://github.com/HackYourFuture/CommandLine) session with Unmesh :balloon:<br>• Advanced data types [Objects] <br>• Array Manipulations <br>• Basic DOM manipulations [img src, innerHTML]<br>• Code commenting|[Reading Week 3](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week3)|[Homework Week 3](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week3/MAKEME.md)|
1211
|4.|• First Git Session with Unmesh :smiling_imp:<br>• JSON<br>• Code debugging using the browser<br>• Functions + JSON/Arrays<br>• Code flow (order of execution) <br>• (capturing user input) <br>• Structuring code files|[Reading Week 4](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week4)|[JS](https://github.com/HackYourFuture/JavaScript/tree/MandT/Week4/MAKEME.md) + [Git Homework Week 4](https://github.com/HackYourFuture/Git/blob/MandT/Lecture-1.md)|

Week2/MAKEME.md

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,3 @@
1-
## Assignment week 2
1+
## Homework Week 2
22

3-
1. Create a function that takes two objects as parameters and compares them. You will actually need to write two functions - one that compares with == and one that compares with ===. Remember that objects can have objects inside of them so you'll need to find a way to compare every element of every object (types and values). For example:
4-
5-
```js
6-
var obj1 = {
7-
a: 1,
8-
b: 'this is the letter b',
9-
c: { foo: 'what is a foo anyway',
10-
bar: [1,2,3,4]
11-
}
12-
}
13-
14-
var obj2 = {
15-
a: '1',
16-
b: 'this is the letter b',
17-
c: { foo: 'what is a foo anyway',
18-
bar: [1,2,3,4]
19-
}
20-
}
21-
```
22-
23-
in our example we'll say that obj1 == obj2 is true and obj1 === obj2 is false. Make sure you can see why before you write any code!
24-
25-
2. We saw that we can pass functions as arguments to other functions. Your task is to write a function that takes another function as an argument and runs it.
26-
27-
```js
28-
function foo(func) {
29-
// What to do here?
30-
}
31-
32-
function bar() {
33-
console.log('Hello, I am bar!');
34-
}
35-
36-
foo(bar);
37-
```
38-
39-
40-
Write some code to test two arrays for equality using == and ===. Test the following:
41-
```
42-
var x = [1,2,3];
43-
var y = [1,2,3];
44-
var z = y;
45-
```
46-
What do you think will happen with x == y, x === y and z == y and z == x? Prove it!
47-
Don't cheat! Seriously - try it first.
48-
http://jsfiddle.net/jimschubert/85M4z/
49-
http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript
50-
51-
3. https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator
52-
53-
4. https://www.freecodecamp.com/challenges/record-collection
54-
55-
5. https://www.freecodecamp.com/challenges/iterate-over-arrays-with-map
56-
57-
6. We did the following example in class:
58-
59-
```js
60-
var o1 = { foo: 'bar' };
61-
var o2 = { foo: 'bar' };
62-
var o3 = o2;
63-
```
64-
Show that changing o2 changes o3 (or not) and changing o2 changes o3 (or not).
65-
66-
Does the order that you assign (o3 = o2 or o2 = o3) matter?
67-
68-
### Some further reading:
69-
Have a look at https://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/
70-
71-
'Coerce' means to try to change - so coercing `var x = '6'` to number means means trying to change the type to number temporarily.
3+
The homework for Week 2 has been moved to Week 3.

Week3/MAKEME.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,84 @@
1-
# Homework Week 3
1+
# Homework Week 3 (moved over from Week 2)
2+
3+
1. Create a function that takes two objects as parameters and compares them. You will actually need to write two functions - one that compares with `==` and one that compares with `===`. Remember that objects can have objects inside of them so you'll need to find a way to compare every element of every object (types and values). For example:
4+
5+
```js
6+
var obj1 = {
7+
a: 1,
8+
b: 'this is the letter b',
9+
c: { foo: 'what is a foo anyway',
10+
bar: [1,2,3,4]
11+
}
12+
}
13+
14+
var obj2 = {
15+
a: '1',
16+
b: 'this is the letter b',
17+
c: { foo: 'what is a foo anyway',
18+
bar: [1,2,3,4]
19+
}
20+
}
21+
```
22+
23+
In our example we'll say that `obj1 == obj2` is `true` and `obj1 === obj2` is `false`. Make sure you can see why before you write any code!
24+
25+
2. We saw that we can pass functions as arguments to other functions. Your task is to write a function that takes another function as an argument and runs it.
26+
27+
```js
28+
function foo(func) {
29+
// What to do here?
30+
}
31+
32+
function bar() {
33+
console.log('Hello, I am bar!');
34+
}
35+
36+
foo(bar);
37+
```
38+
39+
40+
Write some code to test two arrays for equality using `==` and `===`. Test the following:
41+
42+
```js
43+
var x = [1,2,3];
44+
var y = [1,2,3];
45+
var z = y;
46+
```
47+
What do you think will happen with `x == y`, `x === y` and `z == y` and `z == x`? Prove it!
48+
49+
> Don't cheat! Seriously - try it first.
50+
51+
Check out this [Fiddle](http://jsfiddle.net/jimschubert/85M4z/)
52+
53+
And this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript)
54+
55+
**Some freeCodeCamp challenges:**
56+
57+
3. [Comparisons with the Logical And Operator](https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator)
58+
59+
4. [Record Collection](https://www.freecodecamp.com/challenges/record-collection)
60+
61+
5. [Iterate over Arrays with map](https://www.freecodecamp.com/challenges/iterate-over-arrays-with-map)
62+
63+
6. We did the following example in class:
64+
65+
```js
66+
var o1 = { foo: 'bar' };
67+
var o2 = { foo: 'bar' };
68+
var o3 = o2;
69+
```
70+
Show that changing `o2` changes `o3` (or not) and changing `o2` changes `o3` (or not).
71+
72+
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter?
73+
74+
### Some further reading:
75+
76+
Have a look at [The Secret Life of JavaScript Primitives](https://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/)
77+
78+
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
79+
80+
81+
<!-- Original Week 3 homework
282
383
## Read:
484
- https://github.com/HackYourFuture/JavaScript/blob/master/Week3/README.md
@@ -17,7 +97,7 @@ And just for fun ... https://www.freecodecamp.com/challenges/sum-all-numbers-in-
1797
1898
And a custom DOM manipulation challenge :mortar_board:
1999
20-
1. Open a new js file and start by declaring in array with in there 10 strings. These strings should be of book title's you have read (or made up) and be lowercase without spaces or special characters so that you can use these later as Id's. (Example: Harry Potter's - The Chamber of Secrets --> `harry_potter_chamber_secrets`).
100+
1. Open a new js file and start by declaring in array with in there 10 strings. These strings should be of book title's you have read (or made up) and be lowercase without spaces or special characters so that you can use these later as Id's. (Example: Harry Potter's - The Chamber of Secrets -> `harry_potter_chamber_secrets`).
21101
22102
2. Create a basic html file called inxed.html and use it to load the js file, confirm the console.log show the array. (This is for debugging and making sure everything is in order. Delete it later when you're done :))
23103
@@ -29,4 +109,6 @@ And a custom DOM manipulation challenge :mortar_board:
29109
30110
6. Beautify your html page with css, add sources and alts to each of the images.
31111
32-
7. __Optional (expert)__ Download book covers for each book, construct a new Object which has as keys the bookId's again, and as value the path to the image source (e.g. `{"harry_potter_blabla": "./img/harry_potter_blabla.jpg", ...}`). Now loop over these entries (_hint: `Object.keys(objectName)` gives you an array containing the keys_). Then write a function which places an image at the corresponding `li` element. Remember that Objects are not ordered, so you cannot guarantee that the first key is the first `li` element. (_Hint: you could give each `li` item an `id` tag by modifying the function you made before_)
112+
7. __Optional (expert)__ Download book covers for each book, construct a new Object which has as keys the bookId's again, and as value the path to the image source (e.g. `{"harry_potter_blabla": "./img/harry_potter_blabla.jpg", ...}`). Now loop over these entries (_hint: `Object.keys(objectName)` gives you an array containing the keys_). Then write a function which places an image at the corresponding `li` element. Remember that Objects are not ordered, so you cannot guarantee that the first key is the first `li` element. (_Hint: you could give each `li` item an `id` tag by modifying the function you made before_)
113+
114+
-->

0 commit comments

Comments
 (0)