Skip to content

Translation of the article "Functions" into Lithuanian #108

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 18 commits into from
Jul 13, 2022
Original file line number Diff line number Diff line change
@@ -1 +1 @@
No difference.
Abi funkcijos veikia vienodai, skirtumų nėra.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 4

---

# Is "else" required?
# Ar "else" yra privalomas?

The following function returns `true` if the parameter `age` is greater than `18`.
Ši funkcija grąžina `true`, jei parametras `age` yra didesnis nei `18`.

Otherwise it asks for a confirmation and returns its result:
Priešingu atveju ji prašo patvirtinimo per `confirm` ir grąžina rezultatą:

```js
function checkAge(age) {
Expand All @@ -15,13 +15,13 @@ function checkAge(age) {
*!*
} else {
// ...
return confirm('Did parents allow you?');
return confirm('Ar tėvai leido?');
}
*/!*
}
```

Will the function work differently if `else` is removed?
Ar ši funkcija veiks kitaip, jei `else` bus pašalinta?

```js
function checkAge(age) {
Expand All @@ -30,9 +30,9 @@ function checkAge(age) {
}
*!*
// ...
return confirm('Did parents allow you?');
return confirm('Ar tėvai leido?');
*/!*
}
```

Is there any difference in the behavior of these two variants?
Ar yra nors vienas šio varianto elgsenos skirtumas?
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Using a question mark operator `'?'`:
Naudojant operatorių `?`:

```js
function checkAge(age) {
return (age > 18) ? true : confirm('Did parents allow you?');
return (age > 18) ? true : confirm('Ar tėvai leido?');
}
```

Using OR `||` (the shortest variant):
Naudojant operatorių `||` (trumpiausias variantas):

```js
function checkAge(age) {
return (age > 18) || confirm('Did parents allow you?');
return (age > 18) || confirm('Ar tėvai leido?');
}
```

Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
Atkreipkite dėmesį, kad skliaustai aplink `age > 18` yra neprivalomi. Jie skirti geresniam kodo skaitomumui užtikrinti.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ importance: 4

---

# Rewrite the function using '?' or '||'
# Perrašykite funkciją naudodami operatorių '?' arba '||'

The following function returns `true` if the parameter `age` is greater than `18`.
Ši funkcija grąžina `true`, jei parametras `age` yra didesnis nei `18`.

Otherwise it asks for a confirmation and returns its result.
Priešingu atveju klausiama `confirm' ir grąžinamas rezultatas.

```js
function checkAge(age) {
if (age > 18) {
return true;
} else {
return confirm('Did parents allow you?');
return confirm('Ar tėvai leido?');
}
}
```

Rewrite it, to perform the same, but without `if`, in a single line.
Perrašykite funkciją taip, kad ji darytų tą patį, bet be `if`, vienoje eilutėje.

Make two variants of `checkAge`:
Sukurkite dvi funkcijos `checkAge` variantus:

1. Using a question mark operator `?`
2. Using OR `||`
1. Naudojant operatorių `?`
2. Naudojant operatorių `||`
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/14-function-basics/3-min/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A solution using `if`:
Sprendimo variantas naudojant `if`:

```js
function min(a, b) {
Expand All @@ -10,12 +10,12 @@ function min(a, b) {
}
```

A solution with a question mark operator `'?'`:
Sprendimo variantas su operatoriumi `?`:

```js
function min(a, b) {
return a < b ? a : b;
}
```

P.S. In the case of an equality `a == b` it does not matter what to return.
P.S. Lygybės `a == b` atveju nesvarbu, ką grąžinti.
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/14-function-basics/3-min/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 1

---

# Function min(a, b)
# Funkcija min(a, b)

Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
Parašykite funkciją `min(a,b)`, kuri grąžina mažesnį iš skaičių `a` ir `b`.

For instance:
Pavyzdžiui:

```js
min(2, 5) == 2
Expand Down
2 changes: 1 addition & 1 deletion 1-js/02-first-steps/14-function-basics/4-pow/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let x = prompt("x?", '');
let n = prompt("n?", '');

if (n < 1) {
alert(`Power ${n} is not supported, use a positive integer`);
alert(`${n} laipsnis nepalaikomas, naudokite natūralų skaičių`);
} else {
alert( pow(x, n) );
}
Expand Down
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/14-function-basics/4-pow/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ importance: 4

---

# Function pow(x,n)
# Funkcija pow(x,n)

Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result.
Sukurkite funkciją `pow(x,n)`, kuri grąžina `x` iki `n` laipsnio. Kitaip tariant, padaugina `x` iš savęs `n` kartų ir grąžina rezultatą.

```js
pow(3, 2) = 3 * 3 = 9
pow(3, 3) = 3 * 3 * 3 = 27
pow(1, 100) = 1 * 1 * ...* 1 = 1
```

Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
Sukurkite svetainę, kuri pateikia užklausas `x` ir `n` ir išveda rezultatą `pow(x,n)`.

[demo]

P.S. In this task the function should support only natural values of `n`: integers up from `1`.
P.S. Šioje užduotyje reikalaujama, kad funkcija palaikytų tik natūraliąsias `n` vertės, t. y. sveikuosius skaičius nuo `1`.
Loading