-
-
Notifications
You must be signed in to change notification settings - Fork 3
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
40a4866
1.2.11
otmon76 3fad7ec
Update 1-js/02-first-steps/11-logical-operators/article.md
otmon76 02780ea
Update 1-js/02-first-steps/11-logical-operators/6-check-if-in-range/t…
otmon76 a60e98f
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76 b062374
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76 ab291f2
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76 78f1df5
Update 1-js/02-first-steps/11-logical-operators/9-check-login/task.md
otmon76 474789e
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76 017bd68
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76 970cbed
Update 1-js/02-first-steps/11-logical-operators/9-check-login/solutio…
otmon76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
1-js/02-first-steps/11-logical-operators/1-alert-null-2-undefined/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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 first OR `||` evaluates its left operand `alert(1)`. That shows the first message with `1`. | ||
2. The `alert` returns `undefined`, so OR goes on to the second operand searching for a truthy value. | ||
3. The second operand `2` is truthy, so the execution is halted, `2` is returned and then shown by the outer alert. | ||
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 OR ve 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
1-js/02-first-steps/11-logical-operators/3-alert-1-null-2/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
1-js/02-first-steps/11-logical-operators/4-alert-and/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
1-js/02-first-steps/11-logical-operators/5-alert-and-or/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
The answer: `3`. | ||
Odpověď zní: `3`. | ||
|
||
```js run | ||
alert( null || 2 && 3 || 4 ); | ||
``` | ||
|
||
The precedence of AND `&&` is higher than `||`, so it executes first. | ||
Operátor AND `&&` 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`. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
1-js/02-first-steps/11-logical-operators/6-check-if-in-range/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
|
||
```js | ||
if (age >= 14 && age <= 90) | ||
if (věk >= 14 && věk <= 90) | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
1-js/02-first-steps/11-logical-operators/7-check-if-out-range/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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) | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
1-js/02-first-steps/11-logical-operators/8-if-question/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff 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 && 1 executes first, giving us the chain: | ||
// Vykoná se. | ||
// Operátor && má vyšší prioritu než ||, | ||
// takže -1 && 1 se 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í' ); | ||
``` | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
1-js/02-first-steps/11-logical-operators/9-check-login/ifelse_task.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 11 additions & 11 deletions
22
1-js/02-first-steps/11-logical-operators/9-check-login/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
|
||
|
||
```js run demo | ||
let userName = prompt("Who's there?", ''); | ||
let uživatelskéJméno = prompt("Kdo je tam?", ''); | ||
|
||
if (userName === 'Admin') { | ||
if (uživatelskéJméno === 'Správce') { | ||
|
||
let pass = prompt('Password?', ''); | ||
let pass = prompt('Heslo?', ''); | ||
otmon76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (pass === 'TheMaster') { | ||
alert( 'Welcome!' ); | ||
if (pass === 'Mistr') { | ||
otmon76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
alert( 'Vítáme vás!' ); | ||
} else if (pass === '' || pass === null) { | ||
otmon76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
alert( 'Canceled' ); | ||
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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.