-
Notifications
You must be signed in to change notification settings - Fork 22
Logical operators #30
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1659a6c
feat: Translation of Logical operators
lenchen1112 92741c9
Update 1-js/02-first-steps/11-logical-operators/2-alert-or/task.md
lenchen1112 0f21ddd
Update 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md
lenchen1112 4d11720
Update 1-js/02-first-steps/11-logical-operators/8-if-question/task.md
lenchen1112 8c5bf6c
Update 1-js/02-first-steps/11-logical-operators/article.md
lenchen1112 6b04965
Update 1-js/02-first-steps/11-logical-operators/article.md
lenchen1112 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| The answer is `2`, that's the first truthy value. | ||
| 答案是 `2`,這是第一個真值。 | ||
|
|
||
| ```js run | ||
| alert( null || 2 || undefined ); | ||
|
|
||
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
13 changes: 7 additions & 6 deletions
13
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,14 @@ | ||
| 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 顯示。 | ||
|
|
||
| 不會顯示 `3`,因為核定根本到不了 `alert(3)`。 | ||
|
|
||
| There will be no `3`, because the evaluation does not reach `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` 是個虛值。而 `&&` 正是尋找虛值並回傳,就此結束。 | ||
|
|
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`. | ||
| 答案是:`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
1 change: 0 additions & 1 deletion
1
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,5 +1,4 @@ | ||
|
|
||
|
|
||
| ```js | ||
| if (age >= 14 && age <= 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
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
18 changes: 9 additions & 9 deletions
18
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
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
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.