Skip to content

Commit 2d864d3

Browse files
authored
Merge pull request #74 from otmon76/1.2.8
Basic operators, maths
2 parents 3b61aa2 + 3fcabd4 commit 2d864d3

File tree

9 files changed

+230
-229
lines changed

9 files changed

+230
-229
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
The answer is:
2+
Odpověď zní:
33

44
- `a = 2`
55
- `b = 2`
@@ -9,10 +9,10 @@ The answer is:
99
```js run no-beautify
1010
let a = 1, b = 1;
1111

12-
alert( ++a ); // 2, prefix form returns the new value
13-
alert( b++ ); // 1, postfix form returns the old value
12+
alert( ++a ); // 2, prefixová notace vrátí novou hodnotu
13+
alert( b++ ); // 1, postfixová notace vrátí starou hodnotu
1414

15-
alert( a ); // 2, incremented once
16-
alert( b ); // 2, incremented once
15+
alert( a ); // 2, zvýšeno jedenkrát
16+
alert( b ); // 2, zvýšeno jedenkrát
1717
```
1818

1-js/02-first-steps/08-operators/1-increment-order/task.md

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

33
---
44

5-
# The postfix and prefix forms
5+
# Postfixová a prefixová notace
66

7-
What are the final values of all variables `a`, `b`, `c` and `d` after the code below?
7+
Jaké jsou konečné hodnoty všech proměnných `a`, `b`, `c` a `d` po provedení uvedeného kódu?
88

99
```js
1010
let a = 1, b = 1;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
The answer is:
1+
Odpověď zní:
22

3-
- `a = 4` (multiplied by 2)
4-
- `x = 5` (calculated as 1 + 4)
3+
- `a = 4` (vynásobí se 2)
4+
- `x = 5` (vypočítá se jako 1 + 4)
55

1-js/02-first-steps/08-operators/2-assignment-result/task.md

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

33
---
44

5-
# Assignment result
5+
# Výsledek přiřazení
66

7-
What are the values of `a` and `x` after the code below?
7+
Jaké jsou hodnoty proměnných `a` a `x` po provedení uvedeného kódu?
88

99
```js
1010
let a = 2;

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ undefined + 1 = NaN // (6)
1616
" \t \n" - 2 = -2 // (7)
1717
```
1818

19-
1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
20-
2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
21-
3. The addition with a string appends the number `5` to the string.
22-
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
23-
5. `null` becomes `0` after the numeric conversion.
24-
6. `undefined` becomes `NaN` after the numeric conversion.
25-
7. Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
19+
1. Sčítání s řetězcem `"" + 1` převede `1` na řetězec: `"" + 1 = "1"`, pak tedy budeme mít `"1" + 0` a použije se stejné pravidlo.
20+
2. Odčítání `-` (stejně jako většina matematických operací) pracuje jen s čísly, takže převede prázdný řetězec `""` na `0`.
21+
3. Sčítání s řetězcem připojí k řetězci číslo `5`.
22+
4. Odčítání vždy převádí operandy na čísla, takže vyrobí z `" -9 "` číslo `-9` (mezery okolo něj se ignorují).
23+
5. `null` se převede na číslo `0`.
24+
6. `undefined` se převede na číslo `NaN`.
25+
7. Když se řetězec převádí na číslo, mezerové znaky se z jeho začátku a konce odříznou. V tomto případě se celý řetězec skládá z mezerových znaků, konkrétně `\t`, `\n` a „obyčejné“ mezery mezi nimi. Stejně jako prázdný řetězec se tedy převede na `0`.

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md

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

33
---
44

5-
# Type conversions
5+
# Typová konverze
66

7-
What are results of these expressions?
7+
Jaké jsou výsledky následujících výrazů?
88

99
```js no-beautify
1010
"" + 1 + 0
@@ -23,4 +23,4 @@ undefined + 1
2323
" \t \n" - 2
2424
```
2525

26-
Think well, write down and then compare with the answer.
26+
Dobře si to promyslete, zapište si výsledky a pak je porovnejte s odpovědí.
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
The reason is that prompt returns user input as a string.
1+
Důvodem je, že funkce `prompt` vrací uživatelský vstup jako řetězec.
22

3-
So variables have values `"1"` and `"2"` respectively.
3+
V proměnných jsou tedy hodnoty po řadě `"1"` a `"2"`.
44

55
```js run
6-
let a = "1"; // prompt("First number?", 1);
7-
let b = "2"; // prompt("Second number?", 2);
6+
let a = "1"; // prompt("První číslo?", 1);
7+
let b = "2"; // prompt("Druhé číslo?", 2);
88

99
alert(a + b); // 12
1010
```
1111

12-
What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
12+
To, co bychom měli udělat, je před sečtením převést řetězce na čísla. Například použít `Number()` nebo před ně uvést `+`.
1313

14-
For example, right before `prompt`:
14+
Například rovnou před `prompt`:
1515

1616
```js run
17-
let a = +prompt("First number?", 1);
18-
let b = +prompt("Second number?", 2);
17+
let a = +prompt("První číslo?", 1);
18+
let b = +prompt("Druhé číslo?", 2);
1919

2020
alert(a + b); // 3
2121
```
2222

23-
Or in the `alert`:
23+
Nebo až při volání `alert`:
2424

2525
```js run
26-
let a = prompt("First number?", 1);
27-
let b = prompt("Second number?", 2);
26+
let a = prompt("První číslo?", 1);
27+
let b = prompt("Druhé číslo?", 2);
2828

2929
alert(+a + +b); // 3
3030
```
3131

32-
Using both unary and binary `+` in the latest code. Looks funny, doesn't it?
32+
V posledním kódu používáme současně unární i binární `+`. Vypadá to legračně, že?

1-js/02-first-steps/08-operators/4-fix-prompt/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Fix the addition
5+
# Opravte sčítání
66

7-
Here's a code that asks the user for two numbers and shows their sum.
7+
Následující kód se zeptá uživatele na dvě čísla a zobrazí jejich součet.
88

9-
It works incorrectly. The output in the example below is `12` (for default prompt values).
9+
Nefunguje však správně. Výstup v níže uvedeném příkladu (pro defaultní hodnoty v dotazech) je `12`.
1010

11-
Why? Fix it. The result should be `3`.
11+
Proč? Opravte jej. Výsledek by měl být `3`.
1212

1313
```js run
14-
let a = prompt("First number?", 1);
15-
let b = prompt("Second number?", 2);
14+
let a = prompt("První číslo?", 1);
15+
let b = prompt("Druhé číslo?", 2);
1616

1717
alert(a + b); // 12
1818
```

0 commit comments

Comments
 (0)