You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Week1/REVIEW.md
+43-5Lines changed: 43 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,14 +95,14 @@ To get the type of a variable, use the following code:
95
95
96
96
```js
97
97
let x =5;
98
-
let typeOfX =typeof x; // -> "number"
98
+
let typeOfX =typeof x; // -> 'number'
99
99
```
100
100
101
101
Note that I've put an asterisk behind 'array'. That is because in JavaScript, array is a special kind of object:
102
102
103
103
```js
104
104
let arr = [1, 2, 3];
105
-
let typeOfArr =typeof arr; // -> "object"
105
+
let typeOfArr =typeof arr; // -> 'object'
106
106
```
107
107
108
108
However, in our communication, we will call these variables arrays.
@@ -115,16 +115,54 @@ Whenever you declare a variable, but you don't set a value, the variable will be
115
115
116
116
```js
117
117
let x;
118
-
console.log(typeof x); // -> "undefined"
118
+
console.log(typeof x); // -> 'undefined'
119
119
```
120
120
121
+
122
+
### Typeof
123
+
124
+
You can use `typeof` to get the type of a certain variable as you have seen in the above section 'Variable types'. As you can see in the following examples it returns the type of data that you have stored in your variable.
125
+
121
126
## Strings
122
127
123
-
>TODO
128
+
In JavaScript you can store a series of characters inside a variable, you then call this a string. You can store all sorts of characters (text/numbers, spaces or phrases) in strings. By using the `''` you define that something is a string. You can also use `""` to create a string. Both are fine as long as you are consistent (just make a choice on which one you prefer and stick to it).
129
+
130
+
```js
131
+
let foo ='42';
132
+
typeof foo //-> 'string'
133
+
134
+
let bar ='I\'m 99 years old ';
135
+
typeof bar //-> 'string'
136
+
```
137
+
138
+
### String indexes and string properties
139
+
The index of a string always starts at 0.
140
+
Strings also have properties, for example `.length` you can use this to find the length of a string.
141
+
142
+
So for example:
143
+
```js
144
+
let baz ='Hello World';
145
+
baz[0]; //-> "H"
146
+
baz.length; //-> 11
147
+
```
148
+
149
+
### String methods
150
+
151
+
>Todo
124
152
125
153
## Numbers
126
154
127
-
>TODO
155
+
All numbers in JavaScript are considered numbers with or without decimal
Copy file name to clipboardExpand all lines: Week2/MAKEME.md
+14-4Lines changed: 14 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
## Homework Week 2
2
2
3
+
>[Here](https://github.com/HackYourFuture/JavaScript/tree/master/Week2/README.md) you find the readings you have to complete before the third lecture.
4
+
3
5
### Step 1: Recap/Read
4
6
5
7
- Have a look at [The Secret Life of JavaScript Primitives](https://javascriptweblog.wordpress.com/2010/09/27/the-secret-life-of-javascript-primitives/)
@@ -49,7 +51,9 @@ if (3 == 3) {
49
51
50
52
11. 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?
51
53
52
-
12. 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
+
12. Create an empty object
55
+
56
+
13. 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:
53
57
54
58
```js
55
59
var obj1 = {
@@ -73,7 +77,7 @@ if (3 == 3) {
73
77
74
78
Note: give this exercise your best shot but don’t spend more than, say, one hour on it.
75
79
76
-
13. 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.
80
+
14. 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.
77
81
78
82
```js
79
83
functionfoo(func) {
@@ -88,7 +92,7 @@ if (3 == 3) {
88
92
```
89
93
90
94
91
-
14. Write some code to test two arrays for equality using `==` and `===`. Test the following:
95
+
15. Write some code to test two arrays for equality using `==` and `===`. Test the following:
92
96
93
97
```js
94
98
var x = [1,2,3];
@@ -106,7 +110,7 @@ Check out this [Fiddle](http://jsfiddle.net/jimschubert/85M4z/). You need to ope
106
110
More insights from this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript).
107
111
108
112
109
-
14. Take a look at the following code:
113
+
16. Take a look at the following code:
110
114
111
115
```js
112
116
var o1 = { foo:'bar' };
@@ -119,6 +123,12 @@ More insights from this [Stack Overflow question](http://stackoverflow.com/quest
119
123
120
124
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter? {Jim Cramer: ???}
121
125
126
+
17. What does the following code return? (And why?)
127
+
```js
128
+
let bar =42;
129
+
typeoftypeof bar;
130
+
```
131
+
122
132
123
133
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
* Objects (*important to really understand them, read this if you are unsure! You may also read chapters 72, 73 and 74 if you have time and want to learn more*):</br>
Copy file name to clipboardExpand all lines: Week2/REVIEW.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
```
4
4
This review covers:
5
+
• Recap Logical operators
6
+
• Typeof
5
7
• Loops (for/while)
6
8
• Functions
7
9
• Advanced data types [Objects]
@@ -31,6 +33,27 @@ This review covers:
31
33
|0|0|1|
32
34
|1|1|1|
33
35
36
+
So you can say that false in combination with `&&` always returns true
37
+
```js
38
+
true&&false//-> false
39
+
false&&true//-> false
40
+
false||true//-> true
41
+
true||false//-> true
42
+
```
43
+
44
+
### Typeof
45
+
46
+
`typeof` always returns the data type in a string.
47
+
48
+
So for example:
49
+
```js
50
+
let bar =42;
51
+
typeof bar //-> 'number'
52
+
typeoftypeof bar; //-> 'string'
53
+
```
54
+
55
+
So the data type of what `typeof` returns is always a string, bar on the other hand is still a number.
56
+
34
57
## Objects
35
58
36
59
Variables that are objects also contain a list of things, but instead of them being in some specific order, they can be assigned to words, called "keys". Instead of "elements" the things that are inside objects are called "properties".
And just for fun ... https://www.freecodecamp.com/challenges/sum-all-numbers-in-a-range
1
+
## Homework Week 3
17
2
3
+
>[Here](https://github.com/HackYourFuture/JavaScript/tree/master/Week3/README.md) you find the readings you have to complete before the fourth lecture.
18
4
5
+
### Step 1: Recap/Read
19
6
7
+
### Step 2: Watch
20
8
21
-
##And a custom DOM manipulation challenge :mortar_board:
9
+
### Step 3: Custom DOM manipulation challenge :mortar_board:
22
10
23
11
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`).
24
12
@@ -33,3 +21,13 @@ And just for fun ... https://www.freecodecamp.com/challenges/sum-all-numbers-in-
33
21
6. Beautify your html page with css, add sources and alts to each of the images.
34
22
35
23
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_)
0 commit comments