Skip to content

Commit 834f3bb

Browse files
authored
Merge pull request #81 from otmon76/1.2.15
Functions
2 parents 3891276 + f89a3fc commit 834f3bb

File tree

9 files changed

+280
-280
lines changed

9 files changed

+280
-280
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
No difference!
1+
Žádný rozdíl v nich není.
22

3-
In both cases, `return confirm('Did parents allow you?')` executes exactly when the `if` condition is falsy.
3+
V obou případech se příkaz `return confirm('Dovolili ti to rodiče?');` spustí právě tehdy, když podmínka za `if` není splněna.

1-js/02-first-steps/15-function-basics/1-if-else-required/task.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ importance: 4
22

33
---
44

5-
# Is "else" required?
5+
# Je nutné „else“?
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
Následující funkce vrátí `true`, jestliže parametr `věk` je větší než `18`.
88

9-
Otherwise it asks for a confirmation and returns its result:
9+
Jinak se zeptá na povolení a vrátí výsledek dotazu:
1010

1111
```js
12-
function checkAge(age) {
13-
if (age > 18) {
12+
function ověřVěk(věk) {
13+
if (věk > 18) {
1414
return true;
1515
*!*
1616
} else {
1717
// ...
18-
return confirm('Did parents allow you?');
18+
return confirm('Dovolili ti to rodiče?');
1919
}
2020
*/!*
2121
}
2222
```
2323

24-
Will the function work differently if `else` is removed?
24+
Bude tato funkce fungovat jinak, bude-li odstraněno `else`?
2525

2626
```js
27-
function checkAge(age) {
28-
if (age > 18) {
27+
function ověřVěk(věk) {
28+
if (věk > 18) {
2929
return true;
3030
}
3131
*!*
3232
// ...
33-
return confirm('Did parents allow you?');
33+
return confirm('Dovolili ti to rodiče?');
3434
*/!*
3535
}
3636
```
3737

38-
Is there any difference in the behavior of these two variants?
38+
Je nějaký rozdíl mezi chováním těchto dvou variant?
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Using a question mark operator `'?'`:
1+
Pomocí operátoru otazníku `'?'`:
22

33
```js
4-
function checkAge(age) {
5-
return (age > 18) ? true : confirm('Did parents allow you?');
4+
function ověřVěk(věk) {
5+
return (věk > 18) ? true : confirm('Dovolili ti to rodiče?');
66
}
77
```
88

9-
Using OR `||` (the shortest variant):
9+
Pomocí OR `||` (kratší varianta):
1010

1111
```js
12-
function checkAge(age) {
13-
return (age > 18) || confirm('Did parents allow you?');
12+
function ověřVěk(věk) {
13+
return (věk > 18) || confirm('Dovolili ti to rodiče?');
1414
}
1515
```
1616

17-
Note that the parentheses around `age > 18` are not required here. They exist for better readability.
17+
Závorky okolo `věk > 18` zde nejsou nutné. Slouží jen k lepší čitelnosti.

1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ importance: 4
22

33
---
44

5-
# Rewrite the function using '?' or '||'
5+
# Přepište funkci pomocí „?“ nebo „||“
66

7-
The following function returns `true` if the parameter `age` is greater than `18`.
7+
Následující funkce vrátí `true`, jestliže parametr `věk` je větší než `18`.
8+
9+
Jinak se zeptá na povolení a vrátí výsledek dotazu:
810

9-
Otherwise it asks for a confirmation and returns its result.
1011

1112
```js
12-
function checkAge(age) {
13-
if (age > 18) {
13+
function ověřVěk(věk) {
14+
if (věk > 18) {
1415
return true;
1516
} else {
16-
return confirm('Did parents allow you?');
17+
return confirm('Dovolili ti to rodiče?');
1718
}
1819
}
1920
```
2021

21-
Rewrite it, to perform the same, but without `if`, in a single line.
22+
Přepište ji, aby dělala totéž, ale bez použití `if` a na jediný řádek.
2223

23-
Make two variants of `checkAge`:
24+
Vytvořte dvě varianty `ověřVěk`:
2425

25-
1. Using a question mark operator `?`
26-
2. Using OR `||`
26+
1. Pomocí operátoru otazníku `?`
27+
2. Pomocí OR `||`

1-js/02-first-steps/15-function-basics/3-min/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A solution using `if`:
1+
Řešení pomocí `if`:
22

33
```js
44
function min(a, b) {
@@ -10,12 +10,12 @@ function min(a, b) {
1010
}
1111
```
1212

13-
A solution with a question mark operator `'?'`:
13+
Řešení pomocí operátoru otazníku `'?'`:
1414

1515
```js
1616
function min(a, b) {
1717
return a < b ? a : b;
1818
}
1919
```
2020

21-
P.S. In the case of an equality `a == b` it does not matter what to return.
21+
P.S. V případě rovnosti `a == b` nezáleží na tom, kterou proměnnou funkce vrátí.

1-js/02-first-steps/15-function-basics/3-min/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 1
22

33
---
44

5-
# Function min(a, b)
5+
# Funkce min(a, b)
66

7-
Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
7+
Napište funkci `min(a,b)`, která vrátí menší ze dvou čísel `a` a `b`.
88

9-
For instance:
9+
Příklady použítí:
1010

1111
```js
1212
min(2, 5) == 2
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11

22
```js run demo
3-
function pow(x, n) {
4-
let result = x;
3+
function mocnina(x, n) {
4+
let výsledek = x;
55

66
for (let i = 1; i < n; i++) {
7-
result *= x;
7+
výsledek *= x;
88
}
99

10-
return result;
10+
return výsledek;
1111
}
1212

1313
let x = prompt("x?", '');
1414
let n = prompt("n?", '');
1515

1616
if (n < 1) {
17-
alert(`Power ${n} is not supported, use a positive integer`);
17+
alert(`${n}-tá mocnina není podporována, zadejte kladné celé číslo`);
1818
} else {
19-
alert( pow(x, n) );
19+
alert( mocnina(x, n) );
2020
}
2121
```

1-js/02-first-steps/15-function-basics/4-pow/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ importance: 4
22

33
---
44

5-
# Function pow(x,n)
5+
# Funkce mocnina(x,n)
66

7-
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.
7+
Napište funkci `mocnina(x,n)`, která vrátí `x` umocněné na `n`-tou. Nebo, jinak řečeno, vynásobí `x` sebou samým `n`-krát a vrátí výsledek.
88

99
```js
10-
pow(3, 2) = 3 * 3 = 9
11-
pow(3, 3) = 3 * 3 * 3 = 27
12-
pow(1, 100) = 1 * 1 * ...* 1 = 1
10+
mocnina(3, 2) = 3 * 3 = 9
11+
mocnina(3, 3) = 3 * 3 * 3 = 27
12+
mocnina(1, 100) = 1 * 1 * ...* 1 = 1
1313
```
1414

15-
Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`.
15+
Vytvořte webovou stránku, která se zeptá na `x` a `n` a pak zobrazí výsledek `mocnina(x,n)`.
1616

1717
[demo]
1818

19-
P.S. In this task the function should support only natural values of `n`: integers up from `1`.
19+
P.S. V této úloze by funkce měla podporovat jen přirozené hodnoty `n`: celá čísla větší nebo rovna `1`.

0 commit comments

Comments
 (0)