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: Week2/MAKEME.md
+13-76Lines changed: 13 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,24 @@
2
2
3
3
>[Here](https://github.com/SocialHackersCodeSchool/JavaScript/tree/master/Week2/README.md) you find the readings you have to complete before the third lecture.
4
4
5
-
## Step 1: Recap/Read
6
-
7
-
- Have a look at [The Secret Life of JavaScript Primitives](https://www.youtube.com/watch?v=2ZUDcmWW4Hc)
8
-
- Go through the review of [last week](https://github.com/SocialHackersCodeSchool/JavaScript/blob/master/Week1/REVIEW.md) (Work in progress, update this week :wrench:)
9
-
- Go through the review of [this week](https://github.com/SocialHackersCodeSchool/JavaScript/blob/master/Week2/REVIEW.md) (work in progress, update this week :nut_and_bolt:)
10
-
11
-
## Step 2: Watch
5
+
## Step 1: Watch
12
6
13
7
1. If you haven't done already, watch: [What is programming](https://www.khanacademy.org/computing/computer-programming/programming/intro-to-programming/v/programming-intro) Just watch the 2 min video, you do not have to do the entire JavaScript course (It could be useful later on though).
14
8
15
9
2. If you want a refresher on Functions you should see [this video](https://www.youtube.com/watch?v=5nuqALOHN1M).
16
10
17
11
3. If you want a refresher on Objects you should see [this video](https://www.youtube.com/watch?v=mgwiCUpuCxA)
18
12
19
-
## Step 3: JavaScript
13
+
## Step 2: JavaScript
20
14
> For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference
21
15
22
16
1. Create a function that takes 3 arguments and returns the sum of the three arguments.
23
17
24
18
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.)
25
19
26
-
3. Create an object and a function that takes the object as a parameter and prints out all of its names and values.
20
+
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)`
27
21
28
-
4. 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)`
29
-
30
-
5. Can you write the following without the `if` statement, but with just as a single line with `console.log(...);`?
22
+
4. Can you write the following without the `if` statement, but with just as a single line with `console.log(...);`?
31
23
```js
32
24
if (3==3) {
33
25
console.log("true")
@@ -36,60 +28,19 @@ if (3 == 3) {
36
28
}
37
29
```
38
30
39
-
6. Create a function called `vehicle`, like before, but takes another parameter called age, so that `vehicle("blue", 1, 5)` prints "a blue used car"
40
-
41
-
7. Make a list of vehicles, you can add `"motorbike"`, `"caravan"`, `"bike"`, or more.
42
-
43
-
8. How do you get the third element from that list?
44
-
45
-
9. Change the function `vehicle` to use the list of question 4. So that `vehicle("green", 3, 1)` prints "a green new caravan".
46
-
47
-
10. Use the list of vehicles to write an advertisement. So that it prints something like: `"Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes."`. (Hint: use a `for` loop.)
31
+
5. Create a function called `vehicle`, like before, but takes another parameter called age, so that `vehicle("blue", 1, 5)` prints "a blue used car"
48
32
49
-
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 7?
50
-
51
-
12. Create an empty object
52
-
53
-
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:
54
-
55
-
```js
56
-
var obj1 = {
57
-
a:1,
58
-
b:'this is the letter b',
59
-
c: { foo:'what is a foo anyway',
60
-
bar: [1,2,3,4]
61
-
}
62
-
}
63
-
64
-
var obj2 = {
65
-
a:'1',
66
-
b:'this is the letter b',
67
-
c: { foo:'what is a foo anyway',
68
-
bar: [1,2,3,4]
69
-
}
70
-
}
71
-
```
33
+
6. Make a list of vehicles, you can add `"motorbike"`, `"caravan"`, `"bike"`, or more.
72
34
73
-
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!
74
-
75
-
Note: give this exercise your best shot but don’t spend more than, say, one hour on it.
35
+
7. How do you get the third element from that list?
76
36
77
-
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.
37
+
8. Change the function `vehicle` to use the list of question 4. So that `vehicle("green", 3, 1)` prints "a green new caravan".
78
38
79
-
```js
80
-
functionfoo(func) {
81
-
// What to do here?
82
-
}
83
-
84
-
functionbar() {
85
-
console.log('Hello, I am bar!');
86
-
}
87
-
88
-
foo(bar);
89
-
```
39
+
9. Use the list of vehicles to write an advertisement. So that it prints something like: `"Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes."`. (Hint: use a `for` loop.)
90
40
41
+
10. What if you add one more vehicle to the list, can you have that added to the advertisement without changing the code for question 7?
91
42
92
-
15. Write some code to test two arrays for equality using `==` and `===`. Test the following:
43
+
11. Write some code to test two arrays for equality using `==` and `===`. Test the following:
93
44
94
45
```js
95
46
var x = [1,2,3];
@@ -106,21 +57,7 @@ Check out this [Fiddle](http://jsfiddle.net/jimschubert/85M4z/). You need to ope
106
57
107
58
More insights from this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript).
108
59
109
-
110
-
16. Take a look at the following code:
111
-
112
-
```js
113
-
var o1 = { foo:'bar' };
114
-
var o2 = { foo:'bar' };
115
-
var o3 = o2;
116
-
117
-
```
118
-
119
-
Show that changing `o2` changes `o3` (or not) and changing ~~`o2` changes `o3`~~ `o1` changes `o3`(or not).
120
-
121
-
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter? {Jim Cramer: ???}
122
-
123
-
17. What does the following code return? (And why?)
60
+
12. What does the following code return? (And why?)
124
61
```js
125
62
let bar =42;
126
63
typeoftypeof bar;
@@ -129,7 +66,7 @@ typeof typeof bar;
129
66
130
67
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
On freeCodeCamp.com please do the [Basic JavaScript](https://www.freecodecamp.org/map) exercises up and until the __"Shopping List"__ exercise (there are some topics we did not cover but you can do it).
0 commit comments