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

Logical operators#77

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 10 commits intojavascript-tutorial:masterfromotmon76:1.2.11
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
40a4866
1.2.11
otmon76Apr 18, 2022
3fad7ec
Update 1-js/02-first-steps/11-logical-operators/article.md
otmon76Jun 19, 2022
02780ea
Update 1-js/02-first-steps/11-logical-operators/6-check-if-in-range/t…
otmon76Jun 19, 2022
a60e98f
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76Jun 19, 2022
b062374
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76Jun 19, 2022
ab291f2
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76Jun 19, 2022
78f1df5
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76Jun 19, 2022
474789e
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76Jun 19, 2022
017bd68
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76Jun 19, 2022
970cbed
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76Jun 19, 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,4 +1,4 @@
The answer is`2`,that's the first truthy value.
Odpověď zní`2`,což je první pravdivá hodnota.

```js run
alert( null || 2 || undefined );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 5

---

#What's the result of OR?
#Jaký je výsledek OR?

What is the code below going to output?
Co vypíše níže uvedený kód?

```js
alert( null || 2 || undefined );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
The answer: first `1`,then `2`.
Odpověď zní: nejprve `1`,pak `2`.

```js run
alert( alert(1) || 2 || alert(3) );
```

The call to`alert`does not return a value. Or, in other words, it returns `undefined`.
Volání`alert`nevrátí žádnou hodnotu, jinými slovy vrátí `undefined`.

1.The firstOR `||`evaluates its left operand `alert(1)`.That shows the first message with `1`.
2.The `alert`returns `undefined`,so ORgoes on to the second operand searching for a truthy value.
3.The secondoperand `2`is truthy, so the execution is halted,`2`is returned and then shown by the outeralert.
1.PrvníOR `||`vyhodnotí svůj levý operand `alert(1)`.Ten zobrazí první zprávu obsahující `1`.
2.Tento `alert`vrátí `undefined`,takže ORve svém hledání pravdivé hodnoty přejde ke druhému operandu.
3.Druhýoperand `2`je pravdivý, takže vyhodnocení operátoru se zastaví, vrátí`2`a to je pak zobrazeno vnějším `alert`em.

There will be no`3`,because the evaluation does not reach`alert(3)`.
Nezobrazí se`3`,protože vyhodnocení se k`alert(3)` nedostane.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 3

---

#What's the result of OR'ed alerts?
#Jaký je výsledek alertů spojených ORem?

What will the code below output?
Co vypíše níže uvedený kód?

```js
alert( alert(1) || 2 || alert(3) );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
The answer: `null`,because it's the first falsy value from the list.
Odpověď zní `null`,protože je to první nepravdivá hodnota v seznamu.

```js run
alert( 1 && null && 2 );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 5

---

#What is the result of AND?
#Jaký je výsledek AND?

What is this code going to show?
Co vypíše níže uvedený kód?

```js
alert( 1 && null && 2 );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
The answer:`1`,and then `undefined`.
Odpověď zní: nejprve`1`,pak `undefined`.

```js run
alert( alert(1) && alert(2) );
```

The call to `alert` returns `undefined` (it just shows a message, so there's no meaningful return).

Because of that, `&&` evaluates the left operand (outputs `1`), and immediately stops, because `undefined` is a falsy value. And `&&` looks for a falsy value and returns it, so it's done.
Volání `alert` vrátí `undefined` (funkce jen zobrazí zprávu, takže její návratová hodnota nemá žádný význam).

Proto `&&` vyhodnotí první operand (vypíše `1`) a okamžitě se zastaví, protože `undefined` je nepravdivá hodnota. Operátor `&&` hledá první nepravdivou hodnotu a vrátí ji, takže je hotov.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,9 @@ importance: 3

---

#What is the result of AND'ed alerts?
#Jaký je výsledek alertů spojených ANDem?

What will this code show?
Co vypíše níže uvedený kód?

```js
alert( alert(1) && alert(2) );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
The answer: `3`.
Odpověď zní: `3`.

```js run
alert( null || 2 && 3 || 4 );
```

The precedence ofAND `&&`is higher than`||`,so it executes first.
OperátorAND `&&`má vyšší prioritu než`||`,proto se vykoná jako první.

The result of`2 && 3 = 3`,so the expression becomes:
Výsledek`2 && 3 = 3`,takže z výrazu se stane:

```
null || 3 || 4
```

Now the result is the first truthy value: `3`.
Nyní bude výsledkem první pravdivá hodnota: `3`.

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

---

#The result of OR AND OR
#Výsledek OR AND OR

What will the result be?
Jaký bude výsledek?

```js
alert( null || 2 && 3 || 4 );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@


```js
if (age >= 14 &&age <= 90)
if (věk >= 14 &&věk <= 90)
```

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

---

#Check the range between
#Ověřte, zda je hodnota v rozsahu

Write an `if` condition to check that `age` is between`14`and `90`inclusively.
Napište podmínku „if“, která ověří, že proměnná `věk` má hodnotu mezi`14`a `90`včetně.

"Inclusively" means that `age` can reach the edges `14`or `90`.
„Včetně“ znamená, že podmínka je splněna i tehdy, je-li `věk` `14`nebo `90`.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
The first variant:
První varianta:

```js
if (!(age >= 14 &&age <= 90))
if (!(věk >= 14 &&věk <= 90))
```

The second variant:
Druhá varianta:

```js
if (age < 14 ||age > 90)
if (věk < 14 ||věk > 90)
```

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

---

#Check the range outside
#Ověřte, zda hodnota je mimo rozsah

Write an `if` condition to check that `age` is NOT between`14`and `90`inclusively.
Napište podmínku „if“, která ověří, zda proměnná `věk` NENÍ mezi`14`a `90`včetně.

Create two variants: the first one usingNOT `!`,the second one -- without it.
Vytvořte dvě varianty: první bude používatNOT `!`,druhá se obejde bez něj.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
The answer: the first and the third will execute.
Odpověď zní: vykoná se první a třetí `alert`.

Details:
Podrobnosti:

```js run
//Runs.
//The result of-1 || 0 = -1,truthy
if (-1 || 0) alert( 'first' );
//Vykoná se.
//Výsledek-1 || 0 = -1,tedy pravda.
if (-1 || 0) alert( 'první' );

//Doesn't run
// -1 && 0 = 0,falsy
if (-1 && 0) alert( 'second' );
//Nevykoná se.
// -1 && 0 = 0,nepravda.
if (-1 && 0) alert( 'druhý' );

//Executes
//Operator &&has a higher precedence than ||
//so -1 && 1executes first, giving us the chain:
//Vykoná se.
//Operátor &&má vyšší prioritu než ||,
//takže -1 && 1se vykoná jako první, což dává tento řetězec:
// null || -1 && 1 -> null || 1 -> 1
if (null || -1 && 1) alert( 'third' );
if (null || -1 && 1) alert( 'třetí' );
```

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

---

#A question about "if"
#Otázka na „if“

Which of these `alert`s are going to execute?
Který z těchto `alert`ů se vykoná?

What will the results of the expressions be inside `if(...)`?
Jaké budou výsledky výrazů uvnitř `if(...)`?

```js
if (-1 || 0) alert( 'first' );
if (-1 && 0) alert( 'second' );
if (null || -1 && 1) alert( 'third' );
if (-1 || 0) alert( 'první' );
if (-1 && 0) alert( 'druhý' );
if (null || -1 && 1) alert( 'třetí' );
```

View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@


```js run demo
letuserName = prompt("Who's there?", '');
letuživatelskéJméno = prompt("Kdo je tam?", '');

if (userName === 'Admin') {
if (uživatelskéJméno === 'Správce') {

letpass = prompt('Password?', '');
letheslo = prompt('Heslo?', '');

if (pass === 'TheMaster') {
alert( 'Welcome!' );
} else if (pass === '' ||pass === null) {
alert( 'Canceled' );
if (heslo === 'Vládce') {
alert( 'Vítáme vás!' );
} else if (heslo === '' ||heslo === null) {
alert( 'Zrušeno' );
} else {
alert( 'Wrong password' );
alert( 'Špatné heslo' );
}

} else if (userName === '' ||userName === null) {
alert( 'Canceled' );
} else if (uživatelskéJméno === '' ||uživatelskéJméno === null) {
alert( 'Zrušeno' );
} else {
alert( "I don't know you" );
alert( "Neznám vás" );
}
```

Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.
Všimněte si svislého odsazení uvnitř bloků `if`. Není technicky vyžadováno, ale činí kód čitelnějším.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp