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: Week3/MAKEME.md
+48-42Lines changed: 48 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -36,86 +36,92 @@ Provide feedback to the homework of last week to one of your fellow students. Yo
36
36
-[Loops (for/while)](../fundamentals/loops.md)
37
37
-[Functions](../fundamentals/functions.md)
38
38
-[Scope](../fundamentals/scope.md)
39
-
39
+
40
40
## Step 2: Watch
41
41
42
-
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)
42
+
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)
43
43
Just watch the 2 min video, you do not have to do the entire JavaScript course (It could be useful later on though).
44
44
45
-
2. Please watch the following parts of the course, [Programming Foundations Fundamentals](https://www.lynda.com/Programming-Foundations-tutorials/Welcome/83603/90426-4.html) on Lynda.com (if you don't have access to Lynda yet ask Gijs):
45
+
2. Please watch the following parts of the course, [Programming Foundations Fundamentals](https://www.lynda.com/Programming-Foundations-tutorials/Welcome/83603/90426-4.html) on Lynda.com (if you don't have access to Lynda yet ask Gijs):
46
46
<br>**4. Writing Conditional Code**
47
47
<br>**5. Modular Code**
48
48
<br>**6. Iteration: Writing Loops**
49
49
<br>**7. More About Strings**
50
50
<br>**8. Collections**
51
-
<br>**11. When Things Go Wrong**
51
+
<br>**11. When Things Go Wrong**
52
52
53
-
## Step 3: Rover the Robot
53
+
## Step 3: Rover the Robot
54
54
55
-
Go and try out this cool game: [roverjs.com](http://roverjs.com), written by one of our HYF teachers, Joost Lubach. There are different levels, see how far you can get!
55
+
Go and try out this cool game: [roverjs.com](http://roverjs.com), written by one of our HYF teachers, Joost Lubach. There are different levels, see how far you can get!
56
56
57
57
## Step 4: String and Array challenges
58
58
59
-
_Deadline Wednesday_
59
+
_Deadline Wednesday_
60
60
61
61
> 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
62
62
63
63
*IMPORTANT NOTE*
64
64
In each assignment write at least two `console.log` statements to verify if your code works correctly. In other words proof that you code works as expected. If you need inspiration look at the steps defined in the assignments from last week.
65
65
66
-
1\.**Strings!**
67
-
1\.1 Let's consider the following string: `let myString = "hello,this,is,a,difficult,to,read,sentence"`
68
-
1\.2 Add the string to your file and console.log it.
69
-
1\.4 Console.log the length of `myString`.
70
-
1\.5 The commas make that the sentence is quite hard to read. Find a way to remove the comma's from the sting and replace them with a spaces
71
-
1\.6 Console.log `myString` to see if you succeeded.
66
+
1\.**Strings!**
67
+
68
+
Consider the following string:
69
+
70
+
```js
71
+
let myString ="hello,this,is,a,difficult,to,read,sentence";
72
+
```
73
+
74
+
1\.1 Add the string to your file and log it.
75
+
1\.2 Log the length of `myString`.
76
+
1\.3 The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces.
77
+
1\.4 Log `myString` to see if you succeeded.
72
78
73
-
2\.**Arrays!**
79
+
2\.**Arrays!**
74
80
75
81
Consider the following array:
76
82
77
83
```js
78
84
let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
79
85
```
80
86
81
-
2\.1 Add a statement that adds Mauro's favorite animal ('turtle') to the existing array
82
-
2\.2 Log your new array!
83
-
2\.3 Now add Jim's favorite animal to the array, its a 'meerkat', but make sure it will be placed after 'blowfish' and before 'capricorn'.
84
-
2\.4 Write a console.log statement that explains in words _you think_ the new value of the array is.
85
-
2\.5 Log your new new array!
86
-
2\.6 Log the length of the array, add a message: "The array has a length of: "(here you should show the length of the array)
87
-
2\.7 Jason does not like giraffes, delete this animal from the array
88
-
2\.8 Again log your new array.
89
-
2\.9 Now if unlike Jim, you don't like meerkats and you want to delete it from the array, but you don't know the position or the `index` of the item in the array, how can you find it?
90
-
2\.10 Log the index of meerkat to the console. Add a message so it says: "The item you are looking for is at index: " (here you should show the index of the item)
87
+
2\.1 Add a statement that adds Mauro's favorite animal *'turtle'* to the existing array.
88
+
2\.2 Log your new array!
89
+
2\.3 Now add Jim's favorite animal to the array, it's *'meerkat'*, but make sure it will be placed after *'blowfish'* and before *'capricorn'*.
90
+
2\.4 Write a console.log statement that explains in words _you think_ the new value of the array is.
91
+
2\.5 Log your new array!
92
+
2\.6 Log the length of the array, add a message: *'The array has a length of: '*(here you should show the length of the array).
93
+
2\.7 Jason does not like *'giraffe'*, delete this animal from the array.
94
+
2\.8 Again log your new array.
95
+
2\.9 Now if unlike Jim, you don't like *'meerkat'* and you want to delete it from the array, but you don't know the position or the `index` of the item in the array, how can you find it?
96
+
2\.10 Log the index of *'meerkat'*. Add a message so it says: *'The item you are looking for is at index: '* (here you should show the index of the item).
91
97
92
98
## More JavaScript :tada:
93
99
94
-
1. Create a function that takes 3 arguments and returns the sum of the three arguments.
100
+
1. Create a function that takes 3 arguments and returns the sum of the these arguments.
95
101
96
-
2. Create a function named `colorCar` that receives a color, and prints out, "a red car" for example.
102
+
2. Create a function named `colorCar` that receives a color, and prints out, *'a red car'* for example.
97
103
98
-
3. Create an object and a function that takes the object as a parameter and prints out all of its names and values.
104
+
3. Create an object and a function that takes the object as a parameter and prints out all of its properties and values.
99
105
100
-
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)`
106
+
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)`
101
107
102
108
5. Can you write the following without the `if` statement, but with just as a single line with `console.log(...);`?
103
109
104
110
```js
105
111
if (3===3) {
106
-
console.log("true")
112
+
console.log("yes")
107
113
} else {
108
-
console.log("false")
114
+
console.log("no")
109
115
}
110
116
```
111
117
112
-
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"
118
+
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'*
113
119
114
120
7. Make a list of vehicles, you can add `"motorbike"`, `"caravan"`, `"bike"`, or more.
115
121
116
122
8. How do you get the third element from that list?
117
123
118
-
9. Change the function `vehicle` to use the list of question 7. So that `vehicle("green", 3, 1)` prints "a green new caravan".
124
+
9. Change the function `vehicle` to use the list of question 7. So that `vehicle("green", 3, 1)` prints "a green new bike".
119
125
120
126
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.)
121
127
@@ -130,24 +136,24 @@ let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
130
136
14. Add a property to the object you just created that contains the languages that they have taught you.
131
137
132
138
15. Write some code to test two arrays for equality using `==` and `===`. Test the following:
133
-
139
+
134
140
```js
135
141
let x = [1,2,3];
136
142
let y = [1,2,3];
137
143
let z = y;
138
144
```
139
145
140
146
What do you think will happen with `x == y`, `x === y` and `z == y` and `z == x`? Prove it!
141
-
147
+
142
148
> Don't cheat! Seriously - try it first.
143
-
149
+
144
150
145
151
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.
146
152
147
153
More insights from this [Stack Overflow question](http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript).
148
154
149
155
150
-
16. Take a look at the following code:
156
+
16. Take a look at the following code:
151
157
152
158
```js
153
159
let o1 = { foo:'bar' };
@@ -156,19 +162,19 @@ let favoriteAnimals = ['blowfish', 'capricorn', 'giraffe'];
156
162
157
163
```
158
164
159
-
Show that changing `o2` changes `o3` (or not) and changing `o1` changes `o3`(or not).
160
-
165
+
Show that changing `o2` changes `o3` (or not) and changing `o1` changes `o3`(or not).
166
+
161
167
Does the order that you assign (`o3 = o2` or `o2 = o3`) matter?
162
168
163
169
17. What does the following code return? (And why?)
164
170
165
171
```js
166
-
let bar = 42;
172
+
let bar = 42;
167
173
typeof typeof bar;
168
174
```
169
175
170
-
171
-
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
176
+
177
+
> ‘Coerce' means to try to change - so coercing `var x = '6'` to number means trying to change the type to number temporarily.
0 commit comments