Skip to content

Commit b043ea7

Browse files
committed
works
1 parent d813c3d commit b043ea7

File tree

31 files changed

+584
-392
lines changed

31 files changed

+584
-392
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
Backticks embed the expression inside `${...}` into the string.
3+
4+
```js run
5+
let name = "Ilya";
6+
7+
// the expression is a number 1
8+
alert( `hello ${1}` ); // Hello, 1
9+
10+
// the expression is a variable, embed it
11+
alert( `hello ${name}` ); // Hello, Ilya
12+
13+
// the expression is a string "name"
14+
alert( `hello ${"name"}` ); // Hello, name
15+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
importance: 5
2+
3+
---
4+
5+
# String quotes
6+
7+
What is the output of the script?
8+
9+
```js
10+
let name = "Ilya";
11+
12+
alert( `hello ${1}` ); // ?
13+
14+
alert( `hello ${"name"}` ); // ?
15+
16+
alert( `hello ${name}` ); // ?
17+
```

1-js/4-data-structures/4-object/1-hello-object/solution.md renamed to 1-js/2-first-steps/07-types/2-hello-object/solution.md

File renamed without changes.

1-js/4-data-structures/4-object/1-hello-object/task.md renamed to 1-js/2-first-steps/07-types/2-hello-object/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importance: 3
1+
importance: 5
22

33
---
44

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
```js run
4+
let salaries = {
5+
John: 100,
6+
Ann: 160,
7+
Pete: 130
8+
}
9+
10+
let sum = 0;
11+
for(let key in salaries) {
12+
sum += salaries[key];
13+
}
14+
15+
alert(sum); // 390
16+
```
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
importance: 5
2+
3+
---
4+
5+
# Sum object properties
6+
7+
We have an object storing salaries of our team:
8+
9+
```js
10+
let salaries = {
11+
John: 100,
12+
Ann: 160,
13+
Pete: 130
14+
}
15+
```
16+
17+
Write the code to sum all salaries and store in the variable `sum`. Should be `390` in the example above.
18+
19+
Use `for..in` loop to iterate over the object.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
```js run
4+
let salaries = [ 100, 160, 130 ];
5+
6+
let sum = 0;
7+
for(let salary of salaries) {
8+
sum += salary;
9+
}
10+
11+
alert( sum ); // 390
12+
```
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
importance: 5
2+
3+
---
4+
5+
# Sum the array
6+
7+
Write the code to get the sum of the array using `for..of` loop and store in the variable `sum`:
8+
9+
```js
10+
let salaries = [ 100, 160, 130 ];
11+
```
12+
13+
Should be `390` here.

1-js/2-first-steps/07-types/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Besides regular numbers there are so-called "special numeric values" which also
3939
`NaN` is sticky. Any further operation on `NaN` would give `NaN`:
4040

4141
```js run
42-
alert( "not a number" * 2 + 5 - 9 ); // still NaN
42+
alert( "not a number" * 2 + 5 - 9 ); // NaN
4343
```
4444

4545
So, in a long mathematical expression if we have `NaN` in one place, it propagates to the whole result.
@@ -66,7 +66,7 @@ In JavaScript, there are 3 types of quotes.
6666
6767
1. Double quotes: `"Hello"`.
6868
2. Single quotes: `'Hello'`.
69-
3. Backtricks: <code>&#96;Hello&#96;</code>.
69+
3. Backticks: <code>&#96;Hello&#96;</code>.
7070
7171
Double and single quotes are similar, "simple" quotes.
7272
@@ -178,7 +178,7 @@ let user = {
178178
};
179179
```
180180

181-
The `user` object can be imagined as an information shelf with two items labelled "name" and "age".
181+
The `user` object can be imagined as a cabinet with two signed files labelled "name" and "age".
182182

183183
![user object](object-user.png)
184184

1-js/2-first-steps/08-type-conversions/article.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ alert(typeof a); // string
4848

4949
The string conversion is obvious. A `false` becomes `"false"`, `null` becomes `"null"` etc.
5050

51+
For objects it's a little bit trickier. By default, regular objects are converted like this:
52+
53+
```js run
54+
alert( {} ); [object Object]
55+
```
56+
57+
Although, some object subtypes have their own way of formatting, for instance, arrays turn into the comma-delimited list of items:
58+
59+
```js run
60+
let arr = [1,2,3];
61+
62+
alert( arr ); // 1,2,3
63+
alert( String(arr) === '1,2,3' ); // true
64+
```
65+
66+
Later we'll see how to create custom rules for string conversions for our objects.
67+
5168
## Numeric conversion
5269

5370
Numeric conversion happens in mathematical functions and expressions automatically.
@@ -123,7 +140,7 @@ alert( Boolean(" ") ); // any non-empty string, even whitespaces are true
123140
124141
There exist three most widely used type conversions: to string, to number and to boolean.
125142
126-
The conversion to string is usully obvious.
143+
The conversion to string is usully obvious for primitive values and depends on the object type for objects. For instance, arrays turn into a comma-delimited list of elements.
127144
128145
To number follows the rules:
129146

0 commit comments

Comments
 (0)