Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Basic operators, maths#74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
danipoma merged 17 commits intojavascript-tutorial:masterfromotmon76:1.2.8
May 17, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
239be5b
1.2.8
otmon76Apr 18, 2022
08106cb
Update 1-js/02-first-steps/08-operators/1-increment-order/solution.md
otmon76May 17, 2022
81d715a
Update 1-js/02-first-steps/08-operators/1-increment-order/solution.md
otmon76May 17, 2022
abf3900
Update 1-js/02-first-steps/08-operators/1-increment-order/task.md
otmon76May 17, 2022
2571325
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
5b7a89b
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
eb3dc1b
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
53ff266
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
58f4a25
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
ef0ce09
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
4dde2aa
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
73d05c6
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
5a7d24a
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
477e8de
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
cdf1bbf
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
459de01
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
3fcabd4
Update 1-js/02-first-steps/08-operators/article.md
otmon76May 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@

The answer is:
Odpověď zní:

- `a = 2`
- `b = 2`
Expand All@@ -9,10 +9,10 @@ The answer is:
```js run no-beautify
let a = 1, b = 1;

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

alert( a ); // 2,incremented once
alert( b ); // 2,incremented once
alert( a ); // 2,zvýšeno jedenkrát
alert( b ); // 2,zvýšeno jedenkrát
```

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 5

---

#The postfix and prefix forms
#Postfixová a prefixová notace

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

```js
let a = 1, b = 1;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
The answer is:
Odpověď zní:

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

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 3

---

#Assignment result
#Výsledek přiřazení

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

```js
let a = 2;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,10 +16,10 @@ undefined + 1 = NaN // (6)
" \t \n" - 2 = -2 // (7)
```

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.
2.The subtraction`-` (like most math operations) only works with numbers, it converts an empty string`""`to `0`.
3.The addition with a string appends the number`5` to the string.
4.The subtraction always converts to numbers, so it makes `" -9 "`a number`-9` (ignoring spaces around it).
5. `null`becomes `0` after the numeric conversion.
6. `undefined`becomes `NaN` after the numeric conversion.
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`.
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.
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`.
3.Sčítání s řetězcem připojí k řetězci číslo`5`.
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í).
5. `null`se převede na číslo `0`.
6. `undefined`se převede na číslo `NaN`.
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`.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 5

---

#Type conversions
#Typová konverze

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

```js no-beautify
"" + 1 + 0
Expand All@@ -23,4 +23,4 @@ undefined + 1
" \t \n" - 2
```

Think well, write down and then compare with the answer.
Dobře si to promyslete, zapište si výsledky a pak je porovnejte s odpovědí.
24 changes: 12 additions & 12 deletions1-js/02-first-steps/08-operators/4-fix-prompt/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
The reason is thatprompt returns user input as a string.
Důvodem je, že funkce `prompt` vrací uživatelský vstup jako řetězec.

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

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

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

What we should do is to convert strings to numbers before `+`. For example, using`Number()`or prepending them with `+`.
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 `+`.

For example, right before `prompt`:
Například rovnou před `prompt`:

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

alert(a + b); // 3
```

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

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

alert(+a + +b); // 3
```

Using both unary and binary `+` in the latest code. Looks funny, doesn't it?
V posledním kódu používáme současně unární i binární `+`. Vypadá to legračně, že?
12 changes: 6 additions & 6 deletions1-js/02-first-steps/08-operators/4-fix-prompt/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,17 +2,17 @@ importance: 5

---

#Fix the addition
#Opravte sčítání

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

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

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

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

alert(a + b); // 12
```
Loading

[8]ページ先頭

©2009-2025 Movatter.jp