Skip to content

Commit d098c48

Browse files
authored
Merge pull request #137 from jmbothe/master
grammar, usage, punctuation edits, Part 1, sections 2.9 - 2.16
2 parents 3b2b4fc + 6006abd commit d098c48

File tree

8 files changed

+88
-88
lines changed

8 files changed

+88
-88
lines changed

1-js/02-first-steps/09-alert-prompt-confirm/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This part of the tutorial aims to cover JavaScript "as is", without environment-specific tweaks.
44

5-
But still we use a browser as the demo environment. So we should know at least few user-interface functions. In this chapter we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
5+
But still we use a browser as the demo environment. So we should know at least a few user-interface functions. In this chapter we'll get familiar with the browser functions `alert`, `prompt` and `confirm`.
66

77
[cut]
88

@@ -40,7 +40,7 @@ It shows a modal window with a text message, an input field for the visitor and
4040
`default`
4141
: An optional second parameter, the initial value for the input field.
4242

43-
The visitor may type something in the prompt input field and press OK. Or they can cancel the input by pressing a CANCEL button or hitting the `key:Esc` key.
43+
The visitor may type something in the prompt input field and press OK. Or they can cancel the input by pressing the CANCEL button or hitting the `key:Esc` key.
4444

4545
The call to `prompt` returns the text from the field or `null` if the input was canceled.
4646

1-js/02-first-steps/10-ifelse/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
Sometimes we need to perform different actions based on a condition.
44

5-
There is `if` statement for that and also the conditional (ternary) operator for conditional evaluation which we will be referring as “question mark” operator: `"?"` for simplicity.
5+
There is the `if` statement for that and also the conditional (ternary) operator for conditional evaluation which we will be referring as the “question mark” operator: `"?"` for simplicity.
66

77
[cut]
88

99
## The "if" statement
1010

11-
The "if" statement gets a condition, evaluates it and -- if the result is `true` -- executes the code.
11+
The "if" statement gets a condition, evaluates it and, if the result is `true`, executes the code.
1212

1313
For example:
1414

@@ -22,7 +22,7 @@ if (year == 2015) alert( 'You are right!' );
2222

2323
In the example above, the condition is a simple equality check: `year == 2015`, but it can be much more complex.
2424

25-
If there is more than one command to execute -- we can use a code block in figure brackets:
25+
If there is more than one command to execute, we can use a code block in figure brackets:
2626

2727
```js
2828
if (year == 2015) {
@@ -101,7 +101,7 @@ if (year < 2015) {
101101
}
102102
```
103103

104-
In the code above JavaScript first checks `year < 2015`, if it is falsy then goes to the next condition `year > 2015`, and otherwise shows the last `alert`.
104+
In the code above JavaScript first checks `year < 2015`. If it is falsy it then goes to the next condition `year > 2015`, and otherwise shows the last `alert`.
105105

106106
There can be more `else if` blocks. The ending `else` is optional.
107107

@@ -128,7 +128,7 @@ alert(accessAllowed);
128128

129129
The so-called "ternary" or "question mark" operator lets us do that shorter and simpler.
130130

131-
The operator is represented by a question mark `"?"`. The formal term "ternary" means that the operator has 3 operands. It is actually the one and only operator in JavaScript which has that many.
131+
The operator is represented by a question mark `"?"`. The formal term "ternary" means that the operator has three operands. It is actually the one and only operator in JavaScript which has that many.
132132

133133
The syntax is:
134134
```js
@@ -151,7 +151,7 @@ Technically, we can omit parentheses around `age > 18`. The question mark operat
151151
let accessAllowed = age > 18 ? true : false;
152152
```
153153

154-
...But parentheses make the code more readable. So it's recommended to put them.
154+
...But parentheses make the code more readable. So it's recommended to use them.
155155

156156
````smart
157157
In the example above it's possible to evade the question mark operator, because the comparison by itself returns `true/false`:
@@ -214,13 +214,13 @@ let company = prompt('Which company created JavaScript?', '');
214214

215215
Depending on the condition `company == 'Netscape'`, either the first or the second part after `"?"` gets executed and shows the alert.
216216

217-
We don't assign a result to a variable here, the idea is to execute different code depending on the condition.
217+
We don't assign a result to a variable here. The idea is to execute different code depending on the condition.
218218

219219
**It is not recommended to use the question mark operator in this way.**
220220

221-
The notation seem to be shorter than `if`, that appeals to some programmers. But it is less readable.
221+
The notation seems to be shorter than `if`, which appeals to some programmers. But it is less readable.
222222

223-
Here is the same with `if` for comparison:
223+
Here is the same code with `if` for comparison:
224224

225225
```js run no-beautify
226226
let company = prompt('Which company created JavaScript?', '');

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if (1 || 0) { // works just like if( true || false )
4141
}
4242
```
4343

44-
Most of the time, OR `||` is used in `if` to test if *any* of given conditions is correct.
44+
Most of the time, OR `||` is used in an `if` statement to test if *any* of the given conditions is correct.
4545

4646
For example:
4747

@@ -80,13 +80,13 @@ result = value1 || value2 || value3;
8080

8181
The OR `"||"` operator does the following:
8282

83-
- Evalute operands from left to right.
84-
- For each operand, convert it to boolean. If the result is `true`, then stop and return that the original value of that operand.
83+
- Evaluate operands from left to right.
84+
- For each operand, convert it to boolean. If the result is `true`, then stop and return the original value of that operand.
8585
- If all other operands have been assessed (i.e. all were `falsy`), return the last operand.
8686

8787
A value is returned in its original form, without the conversion.
8888

89-
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value found.
89+
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no such value is found.
9090

9191
For instance:
9292

@@ -147,7 +147,7 @@ That leads to some interesting usages compared to a "pure, classical, boolean-on
147147

148148
An assignment is a simple case, other side effects can be involved.
149149

150-
As we can see, such use case is a "shorter way to do `if`". The first operand is converted to boolean and if it's false then the second one is evaluated.
150+
As we can see, such a use case is a "shorter way to do `if`". The first operand is converted to boolean and if it's false then the second one is evaluated.
151151
152152
Most of time it's better to use a "regular" `if` to keep the code easy to understand, but sometimes that can be handy.
153153

@@ -198,7 +198,7 @@ result = value1 && value2 && value3;
198198
199199
The AND `"&&"` operator does the following:
200200
201-
- Evalute operands from left to right.
201+
- Evaluate operands from left to right.
202202
- For each operand, convert it to a boolean. If the result is `false`, stop and return the original value of that operand.
203203
- If all other operands have been assessed (i.e. all were truthy), return the last operand.
204204

1-js/02-first-steps/12-while-for/article.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
We often have a need to perform similar actions many times in a row.
44

5-
For example, when we need to output goods from the list one after another. Or just run the same code for each number from 1 to 10.
5+
For example, when we need to output goods from a list one after another. Or just run the same code for each number from 1 to 10.
66

77
*Loops* are a way to repeat the same part of code multiple times.
88

@@ -19,7 +19,7 @@ while (condition) {
1919
}
2020
```
2121

22-
While the `condition` is `true` -- the `code` from the loop body is executed.
22+
While the `condition` is `true`, the `code` from the loop body is executed.
2323

2424
For instance, the loop below outputs `i` while `i<3`:
2525

@@ -31,7 +31,7 @@ while (i < 3) { // shows 0, then 1, then 2
3131
}
3232
```
3333

34-
A single execution of the loop body is called *an iteration*. The loop in the example above makes 3 iterations.
34+
A single execution of the loop body is called *an iteration*. The loop in the example above makes three iterations.
3535

3636
If there were no `i++` in the example above, the loop would repeat (in theory) forever. In practice, the browser provides ways to stop such loops, and for server-side JavaScript we can kill the process.
3737

@@ -70,7 +70,7 @@ do {
7070
} while (condition);
7171
```
7272

73-
The loop will first execute the body, then check the condition, and while it's truthy -- execute it again and again.
73+
The loop will first execute the body, then check the condition and, while it's truthy, execute it again and again.
7474

7575
For example:
7676

@@ -82,7 +82,7 @@ do {
8282
} while (i < 3);
8383
```
8484

85-
This form of syntax is rarely used except when you want the body of the loop to execute **at least once** regardless of the condition being truthy. Usually, the other form is preferred: `while(…) {…}`.
85+
This form of syntax is rarely used except when you want the body of the loop to execute **at least once** regardless of the condition being truthy. Usually, the other form is preferred: `while(…) {…}`.
8686

8787
## The "for" loop
8888

@@ -231,7 +231,7 @@ alert( 'Sum: ' + sum );
231231

232232
The `break` directive is activated in the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing the control to the first line after the loop. Namely, `alert`.
233233

234-
The combination: "infinite loop + `break` as needed" is great for situations when the condition must be checked not in beginning/end of the loop, but in the middle. Or even in several places of the body.
234+
The combination "infinite loop + `break` as needed" is great for situations when the condition must be checked not in the beginning/end of the loop, but in the middle, or even in several places of the body.
235235

236236
## Continue to the next iteration [#continue]
237237

@@ -266,7 +266,7 @@ for (let i = 0; i < 10; i++) {
266266
}
267267
```
268268

269-
From the technical point of view it's identical to the example above. Surely, we can just wrap the code in the `if` block instead of `continue`.
269+
From a technical point of view it's identical to the example above. Surely, we can just wrap the code in the `if` block instead of `continue`.
270270

271271
But as a side-effect we got one more figure brackets nesting level. If the code inside `if` is longer than a few lines, that may decrease the overall readability.
272272
````
@@ -360,12 +360,12 @@ outer:
360360
for (let i = 0; i < 3; i++) { ... }
361361
```
362362

363-
The `continue` directive can also be used with a label. In this case the execution jumps to the next iteration of the labelled loop.
363+
The `continue` directive can also be used with a label. In this case the execution jumps to the next iteration of the labeled loop.
364364

365365
````warn header="Labels are not a \"goto\""
366-
Labels do not allow to jump into an arbitrary place of code.
366+
Labels do not allow us to jump into an arbitrary place of code.
367367
368-
For example, it is impossible to do like this:
368+
For example, it is impossible to do this:
369369
```js
370370
break label; // jumps to label? No.
371371
@@ -379,12 +379,12 @@ The call to a `break/continue` is only possible from inside the loop, and the la
379379

380380
We covered 3 types of loops:
381381

382-
- `while` -- the condition is checked before each iteration.
383-
- `do..while` -- the condition is checked after each iteration.
384-
- `for(;;)` -- the condition is checked before each iteration, additional settings available.
382+
- `while` -- The condition is checked before each iteration.
383+
- `do..while` -- The condition is checked after each iteration.
384+
- `for(;;)` -- The condition is checked before each iteration, additional settings available.
385385

386386
To make an "infinite" loop, usually the `while(true)` construct is used. Such a loop, just like any other, can be stopped with the `break` directive.
387387

388-
If we don't want to do anything on the current iteration and would like to forward to the next one -- the `continue` directive does it.
388+
If we don't want to do anything on the current iteration and would like to forward to the next one, the `continue` directive does it.
389389

390390
`Break/continue` support labels before the loop. A label is the only way for `break/continue` to escape the nesting and go to the outer loop.

1-js/02-first-steps/13-switch/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ switch(x) {
2828
}
2929
```
3030

31-
- The value of `x` is checked for a strict equality to the value from the first `case`, that is: `value1`, then to the second `value2` and so on.
32-
- If the equality is found -- `switch` starts to execute the code starting from the corresponding `case`, and to the nearest `break` (or to the end of `switch`).
33-
- If no case matched then the `default` code is executed (if exists).
31+
- The value of `x` is checked for a strict equality to the value from the first `case` (that is, `value1`) then to the second (`value2`) and so on.
32+
- If the equality is found, `switch` starts to execute the code starting from the corresponding `case`, until the nearest `break` (or until the end of `switch`).
33+
- If no case is matched then the `default` code is executed (if it exists).
3434

3535
## An example
3636

@@ -58,7 +58,7 @@ switch (a) {
5858

5959
Here the `switch` starts to compare `a` from the first `case` variant that is `3`. The match fails.
6060

61-
Then `4`. That's the match, so the execution starts from `case 4` and till the nearest `break`.
61+
Then `4`. That's a match, so the execution starts from `case 4` until the nearest `break`.
6262

6363
**If there is no `break` then the execution continues with the next `case` without any checks.**
6464

@@ -89,8 +89,8 @@ alert( 'Too big' );
8989
alert( "I don't know such values" );
9090
```
9191

92-
````smart header="Any expresion can be a `switch/case` argument"
93-
Both `switch` and case allow arbitrary expressions.
92+
````smart header="Any expression can be a `switch/case` argument"
93+
Both `switch` and `case` allow arbitrary expressions.
9494

9595
For example:
9696

@@ -141,7 +141,7 @@ switch (a) {
141141
142142
Now both `3` and `5` show the same message.
143143
144-
The ability to "group" cases a side-effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
144+
The ability to "group" cases is a side-effect of how `switch/case` works without `break`. Here the execution of `case 3` starts from the line `(*)` and goes through `case 5`, because there's no `break`.
145145
146146
## Type matters
147147

0 commit comments

Comments
 (0)