Skip to content

Commit 5e8218f

Browse files
committed
clean up
2 parents 4adbe05 + f607f66 commit 5e8218f

15 files changed

Lines changed: 267 additions & 64 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Hack Your JavaScript
44
Here you can find course content and homework for the JavaScript 1,2 and 3 modules
55

6-
## Composition (Module goals)
7-
86
|Week|Topic|Read|Homework|
97
|----|-----|----|--------|
108
|0.|Preparation for your first JavaScript session|[Reading Week 0](https://github.com/HackYourFuture/JavaScript/tree/laurens_thomas/Week0)|-|
@@ -18,8 +16,8 @@ Here you can find course content and homework for the JavaScript 1,2 and 3 modul
1816
|8.|• (re)writing data structures (in JSON)<br> • Closures <br>• Promises|[Reading Week 8](https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week8/README.md)|[Homework Week 8](https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week8/MAKEME.md)|
1917
|9.|• ES6 :hatching_chick: <br>• Object Literals (and other patterns)<br>TEST :boom:|[Reading Week 9](https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week9/README.md)|[Homework Week 9](https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week9/MAKEME.MD)|
2018

19+
__Kind note:__
2120

22-
__Kind note:__<br>
2321
We expect you to __always__ come prepared to the class on Sunday.
2422

2523
## Module goals:
@@ -34,5 +32,6 @@ A tool capable of loading a JSON file and representing it in the DOM
3432
A web app with external data source using at least one API 《〠_〠》
3533

3634
### Overall
37-
A good understanding of all the above mentioned topics. Want to check your Knowledge? Go through the [JavaScript Fundamentals README](https://github.com/HackYourFuture/JavaScript/tree/laurens_thomas/fundamentals) and research/ ask for help (Slack!) with the concepts that are not entirely clear.
35+
A good understanding of all the above mentioned topics. Want to check your Knowledge? Go through the [JavaScript Fundamentals README](https://github.com/HackYourFuture/JavaScript/tree/master/fundamentals) and research/ ask for help (Slack!) with the concepts that are not entirely clear.
36+
3837

Week1/MAKEME.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
1. Create a `.js` file that prints `Hello` when you run it from the command line. (Hint: `node` is the program that can run your JavaScript files.)
44

5-
2. Create a function named `colorCar` that receives a color, and prints out, "a red car" for example. (Hint: put it in your file and run it like before.)
5+
2. Create a function that takes 3 arguments and returns the sum of the three arguments.
6+
7+
3. Create a function named `colorCar` that receives a color, and prints out, "a red car" for example. (Hint: put it in your file and run it like before.)
8+
9+
4. Create an object and a function that takes the object as a parameter and prints out all of its names and values.
610

711
3. Create a function named `vehicleType` that receives a color, and a code, 1 for car, 2 for motorbike. And prints "a blue motorbike" for example when called as `vehicleType("blue", 2)`
812

@@ -18,10 +22,25 @@
1822

1923
9. What if you add one more vehicle to the list, can you have that added to the advertisement without changing the code for question 8?
2024

25+
10. Write a program to answer the following questions:
26+
* Can you store multiple types in an array? Numbers and strings?
27+
* Can you compare inifities? (Not in Eyad's world) - does 6/0 == 10/0? How can you test this?
28+
29+
11. Can you write the following without the `if` statement, but with just as a single line with `console.log(...);`?
30+
```js
31+
if (3 == 3) {
32+
console.log("true")
33+
} else {
34+
console.log("false")
35+
}
36+
```
37+
38+
2139
On freecodecamp.com please try to do all [Basic JavaScript](https://www.freecodecamp.com/challenges/learn-how-free-code-camp-works) exercises (there are some topics we did not cover but you can do it). Please make sure you REALLY understand the exercises below:
2240

2341
- https://www.freecodecamp.com/challenges/multiply-two-decimals-with-javascript
2442
- https://www.freecodecamp.com/challenges/store-multiple-values-in-one-variable-using-javascript-arrays
2543
- https://www.freecodecamp.com/challenges/build-javascript-objects
2644
- https://www.freecodecamp.com/challenges/add-new-properties-to-a-javascript-object
2745
- https://www.freecodecamp.com/challenges/delete-properties-from-a-javascript-object
46+

Week2/MAKEME.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## Assignment week 2
22

3-
1.
4-
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:
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:
54

6-
```
5+
```js
76
var obj1 = {
87
a: 1,
98
b: 'this is the letter b',
@@ -23,10 +22,9 @@ var obj2 = {
2322

2423
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!
2524

26-
2.
27-
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.
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.
2826

29-
```
27+
```js
3028
function foo(func) {
3129
// What to do here?
3230
}
@@ -48,19 +46,15 @@ Don't cheat! Seriously - try it first.
4846
http://jsfiddle.net/jimschubert/85M4z/
4947
http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript
5048

51-
3.
52-
https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator
49+
3. https://www.freecodecamp.com/challenges/comparisons-with-the-logical-and-operator
5350

54-
4.
55-
https://www.freecodecamp.com/challenges/record-collection
51+
4. https://www.freecodecamp.com/challenges/record-collection
5652

57-
5.
58-
https://www.freecodecamp.com/challenges/iterate-over-arrays-with-map
53+
5. https://www.freecodecamp.com/challenges/iterate-over-arrays-with-map
5954

60-
6.
61-
We did the following example in class:
55+
6. We did the following example in class:
6256

63-
```
57+
```js
6458
var o1 = { foo: 'bar' };
6559
var o2 = { foo: 'bar' };
6660
var o3 = o2;
@@ -69,7 +63,6 @@ Show that changing o2 changes o3 (or not) and changing o2 changes o3 (or not).
6963

7064
Does the order that you assign (o3 = o2 or o2 = o3) matter?
7165

72-
-------------------------------------
7366
### Some further reading:
7467
Have a look at https://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/
7568

Week2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Reading material for the third lecture:
22

3-
TBA
3+
## TODO

Week3/MAKEME.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# Homework Week 3
22

33
## Read:
4-
- https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week3/README.md
4+
- https://github.com/HackYourFuture/JavaScript/blob/master/Week3/README.md
55

66
## Challenges:
77
- https://www.freecodecamp.com/challenges/declare-javascript-objects-as-variables
88
- https://www.freecodecamp.com/challenges/make-instances-of-objects-with-a-constructor-function
99
- https://www.freecodecamp.com/challenges/make-unique-objects-by-passing-parameters-to-our-constructor
1010
- https://www.freecodecamp.com/challenges/make-object-properties-private
1111

12+
Loops practice - https://www.freecodecamp.com/challenges/iterate-with-javascript-for-loops
13+
https://www.freecodecamp.com/challenges/iterate-with-javascript-while-loops
14+
https://developer.mozilla.org/en/docs/Web/JavaScript/Closures
15+
16+
And just for fun ... https://www.freecodecamp.com/challenges/sum-all-numbers-in-a-range
17+
1218
And a custom DOM manipulation challenge :mortar_board:
1319

1420
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`).
@@ -23,4 +29,4 @@ And a custom DOM manipulation challenge :mortar_board:
2329

2430
6. Beautify your html page with css, add sources and alts to each of the images.
2531

26-
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_)
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_)

Week3/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11

2-
# Reading material for the fourth lecture
3-
4-
Next week Unmesh will give you your first Git session, please look through the [GIT](https://github.com/HackYourFuture/Gitrepository) and read the learning goals
5-
6-
### Here are some reading materials explaining the material of the previous class in more detail.
7-
- Function call() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
8-
- Function apply() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
9-
- Function bind() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
10-
- Arguments - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/arguments
11-
- Closures - http://javascriptissexy.com/understand-javascript-closures-with-ease/
2+
# Refresher:
3+
• Function call() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
4+
• Function apply() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
5+
• Function bind() - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
6+
• Arguments - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/arguments
127
- Array - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype
138
- strict mode - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
149

10+
Next week Unmesh will give you your first Git session, please look through the [GIT](https://github.com/HackYourFuture/Gitrepository) and read the learning goals
11+
1512
### Read this is preparation for the material taught in the upcoming class
1613
- JSON - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
14+

Week4/MAKEME.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Homework Week 4
22

33
## Read:
4-
- https://github.com/HackYourFuture/JavaScript/blob/laurens_thomas/Week4/README.md
4+
- https://github.com/HackYourFuture/JavaScript/blob/master/Week4/README.md
55

66
## Challenges:
77
- https://www.freecodecamp.com/challenges/using-objects-for-lookups
88
- https://www.freecodecamp.com/challenges/manipulating-complex-objects
99
- https://www.freecodecamp.com/challenges/convert-json-data-to-html
1010

11-
custom challenge:
11+
## Custom challenge:
1212
1. Go to http://www.omdbapi.com/?s=dog and change the word dog in the url to a different common word. You will get as a result, a list of movies with this word in the title. Make sure you get at least 5 results.
1313
2. You can copy the JSON and put it in a string at the top of your js file. Print the title of the 3rd movie in the array to the console.
1414
3. Make a ul with a li for each title (just like you did with the books in the previous assignment

Week4/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ To be read before the 5th lecture:
1919
- Code conventions: http://javascript.crockford.com/code.html
2020
- Objects continued: http://eloquentjavascript.net/06_object.html
2121
- XHTTP requests: https://www.kirupa.com/html5/making_http_requests_js.htm
22+
- Closures: http://javascriptissexy.com/understand-javascript-closures-with-ease/

Week5/MAKEME.md

Lines changed: 86 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212

1313
### JS
1414

15-
You are going to continue using your homework from the previous weeks, and we are going to extend it.
16-
You will have to change some functions you wrote, and depending on how well you did you may or may
17-
not have to change all your code ;).
1815

1916
1. Extend your site with an input element. This is so the user will be able to type in text which will be later used to search the movie database for corresponding movies.
2017

2118
2. Also place a button near the input element. Capture the click even for this button and couple it to a function which grabs the user input from the text field and which initially logs the user input.
2219

2320
3. Make a function which takes a single argument. The function should make an XHR request to `http://www.omdbapi.com/?s=[SEARCH_TERM]` where the search term will be the argument. This argument will be the input the user has given you, so make sure that when the user clicks the button you call this function with the argument.
2421

25-
Look at the [documentation of the API](http://www.omdbapi.com/) and see which other query parameters they support. Mess around with this to see how changing (or adding) parameters modifies your results.
22+
Look at the [documentation of the API](http://www.omdbapi.com/) and see which other query parameters they support. Mess around with this to see how changing (or adding) parameters modifies your results.
2623

2724
Use the code below to make the request (change it if you need to):
2825

29-
```
26+
```js
3027
function loadMovies(){
3128
//This function keeps track of changes to the xhr request
3229
function processRequest() {
@@ -51,10 +48,92 @@ function loadMovies(){
5148
```
5249

5350

54-
4. Use the code from your previous assignment to render the new results. If you have already displayed previous results make sure you clear them (hint: `someElement.removeChild(someChild)`). Make sure you style these results, use a stylesheet for this! Also make sure you do not use javascript to construct static elements. This way you can handle the positioning of elements easier.
51+
4. Use the code from your previous assignment to render the new results. If you have already displayed previous results make sure you clear them (hint: `someElement.removeChild(someChild)`). Make sure you style these results, use a style sheet for this! Also make sure you do not use javascript to construct static elements. This way you can handle the positioning of elements easier.
5552

5653
5. Change the layout of the page so that you only show a list of movie titles on the left side of your page. When the user hovers over a link (or maybe with a click) you want to show the additional information about the movie (poster, year etc.) on the right column.
5754

58-
6. If you have any questions, ask them on slack in the class 9 channel. We want to see more questions as both you and we can learn from them, also try to help eachother!
55+
6. If you have any questions, ask them on slack in the class 9 channel. We want to see more questions as both you and we can learn from them, also try to help each other!
56+
5957

6058
__Bonus__: Write a function takes this array `['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']` and returns an array which only has unique values in it (so it removes the duplicate ones). Make it a 'smart' algorithm that could do it for every array (only strings/number). Try to make it as fast as possible!
59+
60+
61+
### More homework
62+
63+
1. We learned a little bit about callbacks in JS. A callback is simply a function passed to another function that gets executed (run) after a potentially long running operation has completed. There is another function called `setTimeout` that will wait a specified period of time and then execute a function. For example:
64+
65+
```js
66+
function doIt() {
67+
console.log('I am done');
68+
}
69+
setTimeout(doIt, 5000)
70+
```
71+
If you run the above code it will wait 5 seconds and print `I am done`. Please read something about setTimeout on MDN. The first argument to the `setTimeout` call is the callback (`doIt`)
72+
73+
You must write a function that takes 4 arguments.
74+
- A start value
75+
- An end value
76+
- A callback to call if the number is divisible by 3
77+
- A callback to use if the number is divisible by 5
78+
79+
The function should generate an array containing values from start value to end value (inclusive).
80+
81+
Then the function should iterate over the array and call the second argument if the array value is divisible by 3
82+
83+
The function should call the second argument if the array value is divisible by 5
84+
85+
Both functions should be called if the array value is divisible by both 3 and 5
86+
87+
```js
88+
THIS IS FAKE CODE
89+
function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) {
90+
// make array
91+
// start at beginning of array and check if you should call threeCallback or fiveCallback or go on to next
92+
}
93+
threeFive(10, 15, sayThree, sayFive);
94+
95+
// Should create an array [10,11,12,13,14,15]
96+
// and call sayFive, sayThree, sayThree, sayFive - please make sure you see why these calls are made before you start coding
97+
```
98+
99+
100+
2. Please solve this problem using:
101+
https://www.freecodecamp.com/challenges/repeat-a-string-repeat-a-string
102+
1. A for loop
103+
2. A while loop
104+
3. A do loop
105+
106+
3. Some practice with objects
107+
https://www.freecodecamp.com/challenges/construct-javascript-objects-with-functions
108+
109+
4. Nested loops
110+
https://www.freecodecamp.com/challenges/nesting-for-loops
111+
112+
5. We did some work with arrays - `var arr = [1,2,3]`
113+
We can also nest arrays inside arrays like this `var arr2d = [[1,2], [3,4], [5,6]]` (for math people you can think of this as a matrix)
114+
How would you print all the items of an array with 3 dimensions?
115+
How about with K dimensions?
116+
What if you didn't know how deep the array was nested? (You don't have to write code for this but think about it)
117+
118+
6. Here are two functions that look like they do the something similar but they print different results. Please explain what's going on here.
119+
120+
```js
121+
var x = 9;
122+
function f1(val) {
123+
val = val+1;
124+
return val;
125+
}
126+
f1(x);
127+
console.log(x);
128+
129+
130+
var y = { x: 9 };
131+
function f2(val) {
132+
val.x = val.x + 1;
133+
return val;
134+
}
135+
f2(y);
136+
console.log(y);
137+
```
138+
If you are confused please run the code and then consult the Google for "javascript pass by value pass by reference"
139+

Week5/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## Reading for lecture 6
22

3-
43
Before the lecture this Sunday please read:
54

65
- [Learning JavaScript Design Patterns](https://addyosmani.com/resources/essentialjsdesignpatterns/book/#detailnamespacing) up to and including chapter 3
76
- [JavaScript Variable Scope and Hoisting Explained](http://javascriptissexy.com/javascript-variable-scope-and-hoisting-explained/)
87

9-
>If you feel you need preparation for the test I recommend to take a look at the topics listed in the [README](https://github.com/HackYourFuture) of this repo (up to and including week 6) and look up these concepts in your __Smarter Way to Learn JavaScript__ book :books:. It's also useful to go through the reading material and homework of the last weeks.
8+
>If you feel you need preparation for the test I recommend to take a look at the topics listed in the [README](https://github.com/HackYourFuture) of this repo (up to and including week 6) and look up these concepts in your __Smarter Way to Learn JavaScript__ book :books:. It's also useful to go through the reading material and homework of the last weeks.

0 commit comments

Comments
 (0)