Skip to content

Address some possible issues in 1.2.11 #2134

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 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ importance: 3

# Check the range between

Write an "if" condition to check that `age` is between `14` and `90` inclusively.
Write an `if` condition to check that `age` is between `14` and `90` inclusively.

"Inclusively" means that `age` can reach the edges `14` or `90`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ importance: 3

# Check the range outside

Write an `if` condition to check that `age` is NOT between 14 and 90 inclusively.
Write an `if` condition to check that `age` is NOT between `14` and `90` inclusively.

Create two variants: the first one using NOT `!`, the second one -- without it.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
```js run demo
let userName = prompt("Who's there?", '');

if (userName == 'Admin') {
if (userName === 'Admin') {

let pass = prompt('Password?', '');

if (pass == 'TheMaster') {
if (pass === 'TheMaster') {
alert( 'Welcome!' );
} else if (pass == '' || pass == null) {
} else if (pass === '' || pass === null) {
alert( 'Canceled' );
} else {
alert( 'Wrong password' );
}

} else if (userName == '' || userName == null) {
} else if (userName === '' || userName === null) {
alert( 'Canceled' );
} else {
alert( "I don't know you" );
Expand Down
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/11-logical-operators/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The OR `||` operator does the following:

A value is returned in its original form, without the conversion.

In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found.
In other words, a chain of OR `||` returns the first truthy value or the last one if no truthy value is found.

For instance:

Expand All @@ -101,9 +101,9 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl

1. **Getting the first truthy value from a list of variables or expressions.**

For instance, we have `firstName`, `lastName` and `nickName` variables, all optional.
For instance, we have `firstName`, `lastName` and `nickName` variables, all optional (i.e. can be undefined or have falsy values).

Let's use OR `||` to choose the one that has the data and show it (or `anonymous` if nothing set):
Let's use OR `||` to choose the one that has the data and show it (or `"Anonymous"` if nothing set):

```js run
let firstName = "";
Expand All @@ -115,7 +115,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
*/!*
```

If all variables were falsy, `Anonymous` would show up.
If all variables were falsy, `"Anonymous"` would show up.

2. **Short-circuit evaluation.**

Expand Down Expand Up @@ -223,7 +223,7 @@ The precedence of AND `&&` operator is higher than OR `||`.
So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`.
````

````warn header="Don't replace `if` with || or &&"
````warn header="Don't replace `if` with `||` or `&&`"
Sometimes, people use the AND `&&` operator as a "shorter way to write `if`".

For instance:
Expand All @@ -244,7 +244,7 @@ let x = 1;
if (x > 0) alert( 'Greater than zero!' );
```

Although, the variant with `&&` appears shorter, `if` is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use `if` if we want if and use `&&` if we want AND.
Although, the variant with `&&` appears shorter, `if` is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use `if` if we want `if` and use `&&` if we want AND.
````


Expand Down