Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92b6bff

Browse files
authored
Merge pull request HackYourFuture#18 from remarcmij/master
Added VSCode Tips
2 parents 0bb3d2c + 54cdd24 commit 92b6bff

13 files changed

+302
-140
lines changed

VSCodeTips/VSCodeTips.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# VSCode Tips
2+
3+
Here are some tips for getting up to speed with VSCode as you progress through this course.
4+
5+
## Some useful extensions
6+
7+
VSCode can be extended with _extensions_. There are two that we recommend you install from day 1.
8+
9+
**Spell Checker**. We fully understand that you guys sometimes have difficulty with the correct English spelling when choosing names for variables and functions in your JavaScript programs. That is nothing to be ashamed of, but why not get some help from a handy extension?
10+
11+
**ESLint**. This extension can check your JavaScript code for obvious errors, such as undefined variables, unused variables, etc.
12+
13+
### Installation instructions
14+
15+
1. Start up VSCode.
16+
17+
2. Press the last button in the area in left margin (called the Activity Bar), shown below:
18+
<br />![extensions-btn](assets/27857540-5db15d4a-6172-11e7-953f-347c592b4e4f.png)
19+
20+
3. In the input field in the upper left corner, type `code spellchecker` as pictured here:
21+
22+
![Figure 1. Spell checker extension](assets/27807986-f1f76762-6044-11e7-831d-dd2a6551f027.PNG)
23+
24+
(The indication 122K in this picture means that this extension has been downloaded 122,000 times. The five star rating indicates users like it a lot.)
25+
26+
4. Press the green `install` button of **Code Spellchecker**.
27+
5. When the installation has finished, install the ESLint extension in a similar fashion (1.2 million downloads!):
28+
29+
![Figure 2. ESLint extension](assets/27807987-f1fa8406-6044-11e7-8284-b51cd1251921.PNG)
30+
31+
6. When this second extension has finished installing you will notice that the green `install` button changes to a blue `reload` button. But no need to press this button at this time (no harm done if you did).
32+
7. You now need to install a global Node package to support ESLint. Open a terminal window in VSCode by selecting **View**, **Integrated Terminal** from the menu bar.
33+
8. A terminal window opens in the lower half of the VSCode window. In this window, type the command below (on Linux and MacOS systems you may need to prefix this command with `sudo`, e.g. `sudo npm ...`):
34+
35+
```
36+
npm install -g eslint
37+
```
38+
39+
40+
9. Once the installation has finished close VSCode for now.
41+
42+
## Using VSCode for your homework
43+
44+
You’ll get the most out of VSCode if you organise your work in folders, say a folder for each week in the JavaScript module.
45+
46+
(Later in the course you will be “cloning” Git repositories into local folders as the basis for your homework or projects.)
47+
48+
To start work with VSCode in particular folder, start VSCode and open the relevant folder: from the menu, select **File**, **Open Folder**. VSCode will now open this folder to be your "project folder", until you close VSCode or open another folder.
49+
50+
Assuming that you will use the folder for JavaScript work, you need to create a special file inside of it as required by ESlint.
51+
52+
From the menu, select **View**, **Command Palette…** and type `create` as show in the picture below. Select: **Create** '.eslintrc.json' File.
53+
54+
![Figure 3. Create '.eslintrc.json' File](assets/27809404-94afa762-604f-11e7-9d77-0d590bfccc19.png)
55+
56+
The `.eslintrc.json` file will now be created in the project folder. No need to touch this file at this time, it just needs to sit in your project folder. Later in the course you may wish to add additional "rules" to this file for more stringent code checking.
57+
58+
## Creating your JavaScript file
59+
60+
You are now ready to start adding your first JavaScript file.
61+
62+
1. From the menu, select **File**, **New File**. This will create a new, empty file named "Untitled-1".
63+
2. Select **File**, **Save** from the menu and give your file a an appropriate name. Make sure that you give it an extension ".js" to make it a JavaScript file.
64+
3. Start entering your JavaScript code in the new file. Be on the watch out for green squirly underlines. These are warnings from either ESLint or the Spell Checker that something might be wrong.
65+
4. If you see green squirly underlines, hover your mouse pointer over the underlined text and a tooltip will appear that explains what might be wrong.
66+
5. You can also open the "problem" panel by selecting **View**, **Problems** from the menu to see any problems identified.
67+
6. Pay attention also to the lower left part of the VSCode window, i.e. the status bar. It gives an indication of the number of errors and warnings issued. In the picture below there are zero errors, 7 warnings (usually from ESLint) and 14 informational messages (usually from the spell checker).
68+
69+
![Figure 4. Error, warning and message indicators](assets/27809813-64ae6c98-6053-11e7-8b6c-2bec3400ccd3.PNG)
70+
71+
## Some useful short-cut commands
72+
73+
In the previous section we frequently referred you to the menu bar to select commands. As you get more proficient with VSCode you may want to inspect these menus a little closer and take note of the short-cut commands listed in their right margin. For example, the short-cut command for **File**, **New** is listed as Ctrl+N (press `Ctrl` and `N` keys simultaneously) on a Windows or Linux PC and ⌘N on a Mac.
74+
75+
Here are some short-cut commands that you will use many times a day and that we recommend you familiarise yourself with from day 1:
76+
77+
| Operation | Windows | Mac | Linux |
78+
| --------- | ------- | ----- | ----- |
79+
| **Format Document** (make it pretty) | Shift‑Alt‑F | ⇧⌥F| Ctrl‑Shift‑I |
80+
| **Search** (Find)| Ctrl+F | ⌘F | Ctrl+F |
81+
| **Replace** (Find and replace) | Ctrl+H | ⌥⌘F | Ctrl+H |
82+
| **Rename Symbol** (change all names in file to a different name) | F2 | F2 | F2 |
83+
| Open an **Integrated Terminal** window in VSCode | Ctrl+' |\` | Ctrl+' |
84+
85+
- **Format Document**. This command reformats your JavaScript file in a generally accepted standard format, using proper indenting, proper use of spaces, placing of curly braces and more. A neatly formatted document helps you to better understand your own code and your teachers, mentors and fellow students will love your for it too when they review your work.
86+
87+
*With VSCode at your finger tips there is no longer any excuse for submitting poorly formatted homework!*
88+
89+
- **Search**. Search for specified text.
90+
- **Replace**. Replace specified text by some other text.
91+
92+
In the figure below the **Replace** pop-up window is shown. The **Search** pop-up is similar, but with one input field only.
93+
94+
![Figure 5. Search and Replace](assets/27810425-592063d4-605a-11e7-9e29-dfb02f1aed22.png)
95+
96+
- The `Aa` button activates the **Match Case** option.
97+
- The `Ab|` button matches **Whole Words Only**.
98+
- The `.*` button allow you to search using _regular expressions_, which you may encounter in later modules as an advanced JavaScript programming topic.
99+
- The `c-b` button next to the second input field replaces the next occurrence of the matched text.
100+
- The `ab-ac` button replaces **all** occurrences of the matched text.
101+
- The left and right arrows move the cursor to the previous and next match.
102+
- To get rid of the pop-up press `Esc` or press the `x` button.
103+
104+
- **Rename Symbol**. This command renames all occurrences of a JavaScript variable or function name. To do so, move the text cursor to the variable or function name and press F2. A small pop-up window will appear in which you can type a new name. Press Enter to finalise the change or Esc to cancel it.
105+
106+
- **Open an Integrated Terminal window**. We already covered this when we mentioned the **View**, **Integrated Terminal** menu command.
107+
108+
## Running and debugging your code with the VSCode Node debugger
109+
110+
If your JavaScript program is contained in a single file the easiest way to run and examine your code is the start straight in VSCode. Before you can run it you need to do a small preparation. This needs to be done only once per project folder.
111+
112+
1. As illustrated in the figure below, press the **Debug** button in the left margin as indicated by the red triangle.
113+
114+
![debug_1](assets/27833250-393c5a82-60d2-11e7-8713-648ec54abbed.png)
115+
116+
2. You'll see the Debugger Pane in the left hand side of the screen as shown below. Press the "cog" button as indicated by the red triangle.
117+
118+
![debug_2](assets/27833256-3d44da32-60d2-11e7-8f34-0bc0579a10c3.png)
119+
120+
3. Next you will prompted to select an environment. Choose `Node.js`. This produces a JSON file, displayed in a new editor tab with a contents as shown below.
121+
122+
```
123+
{
124+
// Use IntelliSense to learn about possible Node.js debug attributes.
125+
// Hover to view descriptions of existing attributes.
126+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
127+
"version": "0.2.0",
128+
"configurations": [
129+
{
130+
"type": "node",
131+
"request": "launch",
132+
"name": "Launch Program",
133+
"program": "${file}"
134+
}
135+
]
136+
}
137+
```
138+
139+
At this his time no changes are necessary to this file. You can just close the editor tab.
140+
141+
4. Next, press the **Explorer** button in the left margin as indicated by the red triangle in the figure below.
142+
143+
![debug_3](assets/27833921-189a16f4-60d5-11e7-87ee-996cf97921ac.png)
144+
145+
5. Observe that VSCode has created a `.vscode` subfolder in your project folder where it keeps the JSON file just created and potentially other VSCode settings.
146+
6. You can now run your code in the debugger. Switch to the editor tab contains your program and press the green triangular button or, alternatively, press F5.
147+
7. Note that when your program finishes execution the debugger is still active. You can stop it by pressing the square red button.
148+
149+
If you do not really need to debug your program (e.g., by placing breakpoints) etc, you may prefer to run your program in a terminal window. You can open an Integrated Terminal as explained earlier and type:
150+
151+
```
152+
node prog.js
153+
```
154+
155+
Replace `prog.js` with the actual file name of your program.
156+
157+
If you want to run your program in terminal window independent of VSCode you should make sure you are in the same directory as the program you want to run.
158+
159+
160+
### Placing break points and inspecting variables
161+
162+
This is covered in class.
163+
164+
### Further information
165+
166+
Please note that VSCode is actively being developed. At present there is a monthly release cycle, so don't be surprised when you are prompted once a month to update to the latest version. We advise you to update when prompted (naturally, not when you are in the middle something that you don't want interrupted).
167+
168+
You can find detailed information about VSCode at the [VSCode web site](https://code.visualstudio.com/docs).

Week0/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ In week one we will discuss the following topics:
1313
## How to get started
1414
1. Download and install the latest Current version of NodeJS - from https://nodejs.org/en/download/current/
1515
To test that it was installed and running properly, go to your terminal and run the command: node -v You should get the node version printed on your terminal, for example, v8.8.0
16+
2. Although you are free to make you own choice of text/code editor to use during class and homework, we have good experiences with Microsoft's free VSCode editor, which is supported on Windows, Mac and Linux. Please refer to our [VSCode Tips](../VSCodeTips/VSCodeTips.md) for more information.
1617

1718
### Here are resources that we like you to read as a preparation for the coming lecture:
1819

Week2/MAKEME.md

Lines changed: 69 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -48,107 +48,85 @@ In each assignment write at least two `console.log` statements to verify if your
4848
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)`
4949

5050
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+
```
5859

5960
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"
6061

6162
7. Make a list of vehicles, you can add `"motorbike"`, `"caravan"`, `"bike"`, or more.
6263

6364
8. How do you get the third element from that list?
6465

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".
6667

6768
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.)
6869

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?
7071

71-
12. Create an empty object
72+
12. Create an empty object.
7273

7374
13. Create an object that contains the teachers that you have had so far for the different modules.
7475

7576
14. Add a property to the object you just created that contains the languages that they have taught you.
7677

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.
7879

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?
8583
}
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+
function bar() {
86+
console.log('Hello, I am bar!');
9387
}
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-
function foo(func) {
105-
// What to do here?
106-
}
107-
108-
function bar() {
109-
console.log('Hello, I am bar!');
110-
}
111-
112-
foo(bar);
113-
```
88+
89+
foo(bar);
90+
```
11491

11592

11693
16. Write some code to test two arrays for equality using `==` and `===`. Test the following:
11794

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+
```
123100

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+
128105
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.
130107
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).
132109
133110
134111
17. Take a look at the following code:
135112
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;
140117
141-
```
118+
```
142119
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?
146123
147124
18. What does the following code return? (And why?)
148-
```js
149-
let bar = 42;
150-
typeof typeof bar;
151-
```
125+
126+
```js
127+
let bar = 42;
128+
typeof typeof bar;
129+
```
152130
153131
154132
> ‘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:
176154
177155
:star: Additional resources and review: [here](https://github.com/HackYourFuture/JavaScript/tree/master/Week2/REVIEW.md) (work in progress):star:
178156
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.
180+
-->

0 commit comments

Comments
 (0)