Skip to content

Functions #81

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 52 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
60715e9
1.2.15
otmon76 Apr 18, 2022
4efc42b
Update solution.md
otmon76 Jun 27, 2022
c38fee4
Update article.md
otmon76 Jun 27, 2022
ea843c2
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
37926e7
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
c088893
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
25633ea
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
deec629
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
e83cba3
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
2d86dc3
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
a7cf5df
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
96e0a34
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
6284a04
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
6c25b52
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
9dbcf54
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
0dd5146
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
7e4f888
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
52ed0ba
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
7c46b14
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
9f9e845
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
819ddbb
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
0995d74
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
0527b60
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
99f8794
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
a1313db
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
405a4b7
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
9e5a4ea
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
8999849
Update 1-js/02-first-steps/15-function-basics/2-rewrite-function-ques…
otmon76 Jul 13, 2022
f918572
Update 1-js/02-first-steps/15-function-basics/3-min/task.md
otmon76 Jul 13, 2022
223451a
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
9581c5a
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
e433ba2
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
491729c
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
007d3c4
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
3e2d6ce
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
4f2806c
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
9287618
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
393a83f
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
8d1af04
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
7dfa61f
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
b37f9d3
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
655e1fd
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
34f7134
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
4e26f73
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
e2cd6ba
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
4f9e628
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
818abcf
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
493f8ed
Update 1-js/02-first-steps/15-function-basics/article.md
otmon76 Jul 13, 2022
fc3cfbe
Update 1-js/02-first-steps/15-function-basics/1-if-else-required/task.md
otmon76 Jul 13, 2022
a040390
Update 1-js/02-first-steps/15-function-basics/1-if-else-required/solu…
otmon76 Jul 13, 2022
a47afda
Update 1-js/02-first-steps/15-function-basics/2-rewrite-function-ques…
otmon76 Jul 13, 2022
f89a3fc
Merge branch 'master' into 1.2.15
danipoma Jul 13, 2022
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,3 +1,3 @@
No difference!
Žádný rozdíl v nich není.

In both cases, `return confirm('Did parents allow you?')` executes exactly when the `if` condition is falsy.
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.
22 changes: 11 additions & 11 deletions 1-js/02-first-steps/15-function-basics/1-if-else-required/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ importance: 4

---

# Is "else" required?
# Je nutné „else“?

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

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

```js
function checkAge(age) {
if (age > 18) {
function ověřVěk(věk) {
if (věk > 18) {
return true;
*!*
} else {
// ...
return confirm('Did parents allow you?');
return confirm('Dovolili ti to rodiče?');
}
*/!*
}
```

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

```js
function checkAge(age) {
if (age > 18) {
function ověřVěk(věk) {
if (věk > 18) {
return true;
}
*!*
// ...
return confirm('Did parents allow you?');
return confirm('Dovolili ti to rodiče?');
*/!*
}
```

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

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

Using OR `||` (the shortest variant):
Pomocí OR `||` (kratší varianta):

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

Note that the parentheses around `age > 18` are not required here. They exist for better readability.
Závorky okolo `věk > 18` zde nejsou nutné. Slouží jen k lepší čitelnosti.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ importance: 4

---

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

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

Jinak se zeptá na povolení a vrátí výsledek dotazu:

Otherwise it asks for a confirmation and returns its result.

```js
function checkAge(age) {
if (age > 18) {
function ověřVěk(věk) {
if (věk > 18) {
return true;
} else {
return confirm('Did parents allow you?');
return confirm('Dovolili ti to rodiče?');
}
}
```

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

Make two variants of `checkAge`:
Vytvořte dvě varianty `ověřVěk`:

1. Using a question mark operator `?`
2. Using OR `||`
1. Pomocí operátoru otazníku `?`
2. Pomocí OR `||`
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/15-function-basics/3-min/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A solution using `if`:
Řešení pomocí `if`:

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

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

```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. V případě rovnosti `a == b` nezáleží na tom, kterou proměnnou funkce vrátí.
6 changes: 3 additions & 3 deletions 1-js/02-first-steps/15-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)
# Funkce min(a, b)

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

For instance:
Příklady použítí:

```js
min(2, 5) == 2
Expand Down
12 changes: 6 additions & 6 deletions 1-js/02-first-steps/15-function-basics/4-pow/solution.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@

```js run demo
function pow(x, n) {
let result = x;
function mocnina(x, n) {
let výsledek = x;

for (let i = 1; i < n; i++) {
result *= x;
výsledek *= x;
}

return result;
return výsledek;
}

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

if (n < 1) {
alert(`Power ${n} is not supported, use a positive integer`);
alert(`${n}-tá mocnina není podporována, zadejte kladné celé číslo`);
} else {
alert( pow(x, n) );
alert( mocnina(x, n) );
}
```
14 changes: 7 additions & 7 deletions 1-js/02-first-steps/15-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)
# Funkce mocnina(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.
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.

```js
pow(3, 2) = 3 * 3 = 9
pow(3, 3) = 3 * 3 * 3 = 27
pow(1, 100) = 1 * 1 * ...* 1 = 1
mocnina(3, 2) = 3 * 3 = 9
mocnina(3, 3) = 3 * 3 * 3 = 27
mocnina(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)`.
Vytvořte webovou stránku, která se zeptá na `x` a `n` a pak zobrazí výsledek `mocnina(x,n)`.

[demo]

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