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
+69-67Lines changed: 69 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,107 +48,85 @@ In each assignment write at least two `console.log` statements to verify if your
48
48
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)`
49
49
50
50
5. Can you write the following without the `if` statement, but with just as a single line with `console.log(...);`?
51
-
```js
52
-
if (3==3) {
53
-
console.log("true")
54
-
} else {
55
-
console.log("false")
56
-
}
57
-
```
51
+
52
+
```js
53
+
if (3===3) {
54
+
console.log("true")
55
+
} else {
56
+
console.log("false")
57
+
}
58
+
```
58
59
59
60
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"
60
61
61
62
7. Make a list of vehicles, you can add `"motorbike"`, `"caravan"`, `"bike"`, or more.
62
63
63
64
8. How do you get the third element from that list?
64
65
65
-
9. Change the function `vehicle` to use the list of question 4. So that `vehicle("green", 3, 1)` prints "a green new caravan".
66
+
9. Change the function `vehicle` to use the list of question 7. So that `vehicle("green", 3, 1)` prints "a green new caravan".
66
67
67
68
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.)
68
69
69
-
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?
70
+
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 10?
70
71
71
-
12. Create an empty object
72
+
12. Create an empty object.
72
73
73
74
13. Create an object that contains the teachers that you have had so far for the different modules.
74
75
75
76
14. Add a property to the object you just created that contains the languages that they have taught you.
76
77
77
-
<!-- 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:
78
+
15. 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.
78
79
79
-
```js
80
-
let obj1 = {
81
-
a: 1,
82
-
b: 'this is the letter b',
83
-
c: { foo: 'what is a foo anyway',
84
-
bar: [1,2,3,4]
80
+
```js
81
+
function foo(func) {
82
+
// What to do here?
85
83
}
86
-
}
87
-
88
-
let obj2 = {
89
-
a: '1',
90
-
b: 'this is the letter b',
91
-
c: { foo: 'what is a foo anyway',
92
-
bar: [1,2,3,4]
84
+
85
+
functionbar() {
86
+
console.log('Hello, I am bar!');
93
87
}
94
-
}
95
-
```
96
-
97
-
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!
98
-
99
-
Note: give this exercise your best shot but don’t spend more than, say, one hour on it.
100
-
-->
101
-
15. 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.
102
-
103
-
```js
104
-
functionfoo(func) {
105
-
// What to do here?
106
-
}
107
-
108
-
functionbar() {
109
-
console.log('Hello, I am bar!');
110
-
}
111
-
112
-
foo(bar);
113
-
```
88
+
89
+
foo(bar);
90
+
```
114
91
115
92
116
93
16. Write some code to test two arrays for equality using `==` and `===`. Test the following:
117
94
118
-
```js
119
-
let x = [1,2,3];
120
-
let y = [1,2,3];
121
-
let z = y;
122
-
```
95
+
```js
96
+
let x = [1,2,3];
97
+
let y = [1,2,3];
98
+
let z = y;
99
+
```
123
100
124
-
What do you think will happen with `x == y`, `x === y` and `z == y` and `z == x`? Prove it!
125
-
126
-
> Don't cheat! Seriously - try it first.
127
-
101
+
What do you think will happen with`x == y`, `x === y` and `z == y` and `z == x`? Prove it!
102
+
103
+
> Don't cheat! Seriously - try it first.
104
+
128
105
129
-
Check out this [Fiddle](http://jsfiddle.net/jimschubert/85M4z/). You need to open your browser’s Developer Tools to see the console output. Press the Run button in the upper right corner to run the code.
106
+
Check out this [Fiddle](http://jsfiddle.net/jimschubert/85M4z/). You need to open your browser’s Developer Tools to see the console output. Press the Run button in the upper right corner to run the code.
130
107
131
-
More insights from this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript).
108
+
More insights from this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript).
132
109
133
110
134
111
17. Take a look at the following code:
135
112
136
-
```js
137
-
let o1 = { foo:'bar' };
138
-
let o2 = { foo:'bar' };
139
-
let o3 = o2;
113
+
```js
114
+
let o1 = { foo: 'bar' };
115
+
let o2 = { foo: 'bar' };
116
+
let o3 = o2;
140
117
141
-
```
118
+
```
142
119
143
-
Show that changing `o2` changes `o3` (or not) and changing~~`o2` changes `o3`~~`o1` changes `o3`(or not).
144
-
145
-
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter? {Jim Cramer: ???}
120
+
Show that changing `o2` changes `o3` (or not) and changing `o1` changes `o3`(or not).
121
+
122
+
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter?
146
123
147
124
18. What does the following code return? (And why?)
148
-
```js
149
-
let bar =42;
150
-
typeoftypeof bar;
151
-
```
125
+
126
+
```js
127
+
let bar = 42;
128
+
typeof typeof bar;
129
+
```
152
130
153
131
154
132
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
@@ -176,3 +154,27 @@ How to hand in your homework:
176
154
177
155
:star: Additional resources and review: [here](https://github.com/HackYourFuture/JavaScript/tree/master/Week2/REVIEW.md) (work in progress):star:
178
156
157
+
<!-- 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:
158
+
159
+
```js
160
+
let obj1 = {
161
+
a: 1,
162
+
b: 'this is the letter b',
163
+
c: { foo: 'what is a foo anyway',
164
+
bar: [1,2,3,4]
165
+
}
166
+
}
167
+
168
+
let obj2 = {
169
+
a: '1',
170
+
b: 'this is the letter b',
171
+
c: { foo: 'what is a foo anyway',
172
+
bar: [1,2,3,4]
173
+
}
174
+
}
175
+
```
176
+
177
+
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!
178
+
179
+
Note: give this exercise your best shot but don’t spend more than, say, one hour on it.
0 commit comments