-
Notifications
You must be signed in to change notification settings - Fork 183
Logical operators #34
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
tarasyyyk
merged 10 commits into
javascript-tutorial:master
from
Zim123:1_02_11_logical_operators
Jul 16, 2019
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ddffb12
saving progress
Zim123 81b1fd9
saveing progress
Zim123 19f815e
Merge branch 'master' into 1_02_11_logical_operators
Zim123 d3fa813
saving progress
Zim123 bbfdd3d
saving progress
Zim123 483de94
saving progress
Zim123 40f8158
finished translation
Zim123 3e94d80
Merge branch 'master' into 1_02_11_logical_operators
Zim123 903f3ef
crrections
Zim123 f126cba
after review corrections
Zim123 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`. | ||
| Відповідь: спочатку `1`, потім `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`. | ||
| Виклик `alert` не повертає значення. Або, іншими словами, повертає `undefined`. | ||
|
|
||
| 1. The first OR `||` evaluates it's 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. Перший OR `||` обчислює його лівий операнд `alert(1)`. Це показує перше повідомлення з `1`. | ||
| 2. `alert` повертає `undefined`, тому OR переходить до другого операнда, шукаючи правдиве значення. | ||
| 3. Другий операнд `2` є правдивим, тому виконання зупинено, повернуто `2` і потім показано зовнішнім alert. | ||
|
|
||
| There will be no `3`, because the evaluation does not reach `alert(3)`. | ||
| Не буде `3`, тому що обчислення на досягає `alert(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/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
6 changes: 3 additions & 3 deletions
6
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,10 @@ | ||
| The answer: `1`, and then `undefined`. | ||
| Відповідь: `1`, а потім `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). | ||
| Виклик `alert` повертає `undefined` (він просто показує повідомлення, тому не повертається значення, яке б мало сенс). | ||
|
|
||
| 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. | ||
| Через це `&&` обчислює лівий операнд (виводить `1`) і негайно зупиняється, оскільки `undefined` є не правдивим значенням. І `&&` шукає не правдиве значення і повертає його, як це і зроблено. | ||
|
|
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`. | ||
| Відповідь: `3`. | ||
|
|
||
| ```js run | ||
| alert( null || 2 && 3 || 4 ); | ||
| ``` | ||
|
|
||
| The precedence of AND `&&` is higher than `||`, so it executes first. | ||
| Пріоритет AND `&&` вище за `||`, тому він виконується першим. | ||
|
|
||
| The result of `2 && 3 = 3`, so the expression becomes: | ||
| Результат `2 && 3 = 3`, тому вираз стає: | ||
|
|
||
| ``` | ||
| null || 3 || 4 | ||
| ``` | ||
|
|
||
| Now the result is the first truthy value: `3`. | ||
| Тепер результат — перше правдиве значення: `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
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
4 changes: 2 additions & 2 deletions
4
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
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. | ||
| Відповідь: перший і третій виконаються. | ||
|
|
||
| Details: | ||
| Деталі: | ||
|
|
||
| ```js run | ||
| // Runs. | ||
| // The result of -1 || 0 = -1, truthy | ||
| if (-1 || 0) alert( 'first' ); | ||
| // Виконається. | ||
| // Результат -1 || 0 = -1, правдивий | ||
| if (-1 || 0) alert( 'перший' ); | ||
|
|
||
| // Doesn't run | ||
| // -1 && 0 = 0, falsy | ||
| if (-1 && 0) alert( 'second' ); | ||
| // Не виконається | ||
| // -1 && 0 = 0, не правдивий | ||
| if (-1 && 0) alert( 'другий' ); | ||
|
|
||
| // Executes | ||
| // Operator && has a higher precedence than || | ||
| // so -1 && 1 executes first, giving us the chain: | ||
| // Виконається | ||
| // Оператор && має більший приорітет, ніж || | ||
| // тому -1 && 1 виконається першим, даючи нам послідовність: | ||
| // null || -1 && 1 -> null || 1 -> 1 | ||
| if (null || -1 && 1) alert( 'third' ); | ||
| if (null || -1 && 1) alert( 'третій' ); | ||
| ``` | ||
|
|
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
16 changes: 8 additions & 8 deletions
16
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 userName = prompt("Хто там?", ''); | ||
|
|
||
| if (userName == 'Admin') { | ||
|
|
||
| let pass = prompt('Password?', ''); | ||
| let pass = prompt('Пароль?', ''); | ||
|
|
||
| if (pass == 'TheMaster') { | ||
| alert( 'Welcome!' ); | ||
| alert( 'Ласкаво просимо!' ); | ||
| } else if (pass == '' || pass == null) { | ||
| alert( 'Canceled.' ); | ||
| alert( 'Скасовано.' ); | ||
| } else { | ||
| alert( 'Wrong password' ); | ||
| alert( 'Неправильний пароль' ); | ||
| } | ||
|
|
||
| } else if (userName == '' || userName == null) { | ||
| alert( 'Canceled' ); | ||
| alert( 'Скасовано' ); | ||
| } else { | ||
| alert( "I don't know you" ); | ||
| alert( "Я вас не знаю" ); | ||
| } | ||
| ``` | ||
|
|
||
| Note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable. | ||
| Зверніть увагу на вертикальні відступи у блоках `if`. Вони технічно не потрібні, але роблять код читабельним. |
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
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.