Skip to content

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 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 24 commits into from
Aug 4, 2021
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
@@ -1,4 +1,4 @@
The answer is `2`, that's the first truthy value.
Atsakymas yra `2`, pirmoji truthy vertė.

```js run
alert( null || 2 || undefined );
Expand Down
Original file line number Diff line number Diff 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
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/11-logical-operators/2-alert-or/solution.md
Original file line number Diff line number Diff 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 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. 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škodamas truthy vertė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)`.
4 changes: 2 additions & 2 deletions 1-js/02-first-steps/11-logical-operators/2-alert-or/task.md
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The answer: `null`, because it's the first falsy value from the list.
Atsakymas: `null`, nes tai yra pirmoji falsy vertė sąraše.

```js run
alert( 1 && null && 2 );
Expand Down
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 a falsy value. And `&&` looks for a falsy value and returns it, so it's done.
Dėl to `&&` įvertina kairį operandą (parodo `1`), ir iš karto sustoja, nes `undefined` yra falsy vertė. O `&&` ieško falsy vertės ir ją grąžina, ir sustoja.

4 changes: 2 additions & 2 deletions 1-js/02-first-steps/11-logical-operators/4-alert-and/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ importance: 3

---

# What is the result of AND'ed alerts?
# Koks yra IR alerts rezultatas?

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

```js
alert( alert(1) && alert(2) );
Expand Down
Original file line number Diff line number Diff 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 first truthy value: `3`.
Dabar rezultatas yra pirmoji truthy vertė: `3`.

Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 between 14 and 90 inclusively.
Parašykite `if` sąlygą, kuri patikrintų ar `age` nėra tarp 14 ir 90 įskaitant.

Create two variants: the first one using NOT `!`, the second one -- without it.
Sukurkite du variantus: vieną naudojant NE `!`, kitą nenaudojant jo.
20 changes: 10 additions & 10 deletions 1-js/02-first-steps/11-logical-operators/8-if-question/solution.md
Original file line number Diff line number Diff 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 && 1 executes 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' );
```

12 changes: 6 additions & 6 deletions 1-js/02-first-steps/11-logical-operators/8-if-question/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ importance: 5

---

# A question about "if"
# Klausimas apie "if"

Which of these `alert`s are going to execute?
Kurie iš šių `alert`s bus į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' );
```

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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("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