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

Translated the if statements#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
meilune merged 24 commits intojavascript-tutorial:masterfrommeilune:master
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
24 commits
Select commitHold shift + click to select a range
5154490
Update article.md
meiluneJul 27, 2021
f48ad01
Update article.md
meiluneJul 27, 2021
1ebf783
Translated article.md
meiluneJul 27, 2021
063cf63
Translated task.md
meiluneJul 28, 2021
673d6a1
Translated solution.md
meiluneJul 28, 2021
3cec1b7
Translated task.md
meiluneJul 28, 2021
2320cff
Translated solution.md
meiluneJul 28, 2021
a0acd3d
Translated task.md
meiluneJul 28, 2021
a85d7ad
Translated solution.md
meiluneJul 28, 2021
da3283a
Translated task.md
meiluneJul 28, 2021
535e08c
Translated solution.md
meiluneJul 28, 2021
d8bc382
Translated task.md
meiluneJul 29, 2021
419f3a4
Translated solution.md
meiluneJul 29, 2021
50143ee
Translated task.md
meiluneJul 29, 2021
b4be9ee
Translated task.md
meiluneJul 29, 2021
4bcffb3
Translated solution.md
meiluneJul 29, 2021
7fa2669
Translated task.md
meiluneJul 29, 2021
f8cb281
Translated solution.md
meiluneJul 29, 2021
b040cb7
Translated task.md
meiluneJul 29, 2021
bffa68d
Translated solution.md
meiluneAug 4, 2021
e1323a7
Translated ifelse_task.svg
meiluneAug 4, 2021
46f8d2c
Translated ifelse_task.svg
meiluneAug 4, 2021
360ba37
Translated ifelse_task.svg
meiluneAug 4, 2021
a4518ed
Translated ifelse_task.svg
meiluneAug 4, 2021
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 firsttruthyvalue.
Atsakymas yra`2`,pirmojitruthyvertė.

```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?
#Koks bus ARBA rezultatas?

What is the code below going to output?
Ką atiduos žemiau esantis kodas?

```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`.
Atsakymas yra: pirma `1`,tada `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`.
Šaukimas`alert`negrąžina jokios vertės. Arba kitaip sakant, jis grąžina `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 atruthyvalue.
3.The second operand`2`is truthy,so the execution is halted,`2`is returned and then shown by the outer alert.
1.Pirmasis ARBA`||`įvertina kairėje esantį operandą `alert(1)`.Jis parodo žinutę su `1`.
2. `alert`grąžina `undefined`,tad ARBA eina prie sekančio operando ieškodamastruthyvertės.
3.Antrasis operandas`2`yra truthy,tad operacija sustabdoma, grąžinamas`2`ir parodomas per išorinį alert.

There will be no`3`,because the evaluation does not reach `alert(3)`.
Nebebus`3`,nes įvertinimas nepasiekia `alert(3)`.
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?
#Koks bus ARBA alert rezultatas?

What will the code below output?
Ką atiduos žemiau esantis kodas?

```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 falsyvalue from the list.
Atsakymas: `null`,nes tai yra pirmoji falsyvertė sąraše.

```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?
#Koks yra IR rezultatas?

What is this code going to show?
Ką parodys žemiau esantis kodas?

```js
alert( 1 && null && 2 );
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
The answer: `1`,and then `undefined`.
Atsakymas: `1`,ir tada `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).
Šaukimas`alert`grąžina `undefined` (tiesiog parodo žinutę, tad nebus prasmingo grąžinimo).

Because of that,`&&`evaluates the left operand (outputs `1`),and immediately stops, because `undefined`is afalsyvalue. And `&&`looks for afalsyvalue and returns it, so it's done.
Dėl to`&&`įvertina kairį operandą (parodo `1`),ir iš karto sustoja, nes `undefined`yrafalsyvertė. O `&&`ieškofalsyvertės ir ją grąžina, ir sustoja.

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'edalerts?
#Koks yra IRalerts rezultatas?

What will this code show?
Kas parodys kodas esantis žemiau?

```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`.
Atsakymas: `3`.

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

The precedence of AND`&&`is higher than`||`,so it executes first.
IR`&&`pirmenybė yra aukštesnė už`||`,tad jis įvykdomas pirmiau.

The result of`2 && 3 = 3`,so the expression becomes:
Rezultatas yra`2 && 3 = 3`,tad išraiška tampa:

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

Now the result is the firsttruthyvalue: `3`.
Dabar rezultatas yra pirmojitruthyvertė: `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
#ARBA IR ARBA rezultatas

What will the result be?
Koks bus rezultatas?

```js
alert( null || 2 && 3 || 4 );
Expand Down
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
#Patikrinkite intervalą

Write an"if"condition to check that `age`is between `14`and `90`inclusively.
Parašykite"if"sąlygą, kuri patikrintų ar `age`yra tarp `14`ir `90`įskaitant.

"Inclusively" means that `age`can reach the edges`14`or `90`.
"Įskaitant" reiškia, kad `age`gali pasiekti`14`ir `90` ribas.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
The first variant:
Pirmas variantas:

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

The second variant:
Antras variantas:

```js
if (age < 14 || age > 90)
Expand Down
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
#Patikrinkite už intervalo ribų

Write an`if`condition to check that `age`is NOT between14and 90inclusively.
Parašykite`if`sąlygą, kuri patikrintų ar `age`nėra tarp14ir 90įskaitant.

Create two variants: the first one using NOT`!`,the second one -- without it.
Sukurkite du variantus: vieną naudojant NE`!`,kitą nenaudojant jo.
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.
Atsakymas: pirma ir antra bus įvykdytos.

Details:

```js run
//Runs.
//The result of -1 || 0 = -1, truthy
if (-1 || 0) alert( 'first' );
//Paleidžiama.
//Rezultatas iš -1 || 0 = -1, truthy
if (-1 || 0) alert( 'pirmas' );

//Doesn't run
//Nepaleidžiamas
// -1 && 0 = 0, falsy
if (-1 && 0) alert( 'second' );
if (-1 && 0) alert( 'antras' );

//Executes
//Operator &&has a higher precedence than ||
//so -1 && 1executes first, giving us the chain:
//Įvykdomas
//Operatorius &&turi aukštesnį prioritetą negu ||
//tad -1 && 1įvykdomas pirmiau, sukurdamas mums grandinę:
// null || -1 && 1 -> null || 1 -> 1
if (null || -1 && 1) alert( 'third' );
if (null || -1 && 1) alert( 'trečias' );
```

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"
#Klausimas apie "if"

Which of these `alert`sare going to execute?
Kurie iš šių `alert`sbus įvykdyti?

What will the results of the expressions be inside `if(...)`?
Koks bus išraiškų rezultatas viduje `if(...)`?

```js
if (-1 || 0) alert( 'first' );
if (-1 && 0) alert( 'second' );
if (null || -1 && 1) alert( 'third' );
if (-1 || 0) alert( 'pirmas' );
if (-1 && 0) alert( 'antras' );
if (null || -1 && 1) alert( 'trečias' );
```

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
let userName = prompt("Who's there?", '');
let userName = prompt("Kas čia?", '');

if (userName == 'Admin') {

let pass = prompt('Password?', '');
let pass = prompt('Slaptažodis?', '');

if (pass == 'TheMaster') {
alert( 'Welcome!' );
alert( 'Sveiki!' );
} else if (pass == '' || pass == null) {
alert( 'Canceled' );
alert( 'Atšaukta' );
} else {
alert( 'Wrong password' );
alert( 'Neteisingas slaptažodis' );
}

} else if (userName == '' || userName == null) {
alert( 'Canceled' );
alert( 'Atšaukta' );
} else {
alert( "I don't know you" );
alert( "Aš jūsų nepažįstu" );
}
```

Note the vertical indents inside the `if`blocks. They are technically not required, but make the code more readable.
Atkreipkite dėmesį į vertikalius įgilėjimus viduje `if`rinkinio. Techniškai jie nėra būtini, bet jie paverčia kodą lengviau skaitomu.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp