Skip to content
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

Functions #85

Merged
merged 7 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 +1 @@
No difference.
Nie ma żadnej różnicy.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 4

---

# Is "else" required?
# Czy "else" jest wymagane?

The following function returns `true` if the parameter `age` is greater than `18`.
Następująca funkcja zwraca `true` jeżeli parametr `age` jest większy niż `18`.

Otherwise it asks for a confirmation and returns its result:
W przeciwnym razie prosi o potwierdzenie i zwraca wynik:

```js
function checkAge(age) {
Expand All @@ -15,13 +15,13 @@ function checkAge(age) {
*!*
} else {
// ...
return confirm('Did parents allow you?');
return confirm('Czy rodzice ci pozwolili?');
}
*/!*
}
```

Will the function work differently if `else` is removed?
Czy funkcja będzie działać inaczej jeżeli `else` zostanie usunięte?

```js
function checkAge(age) {
Expand All @@ -30,9 +30,9 @@ function checkAge(age) {
}
*!*
// ...
return confirm('Did parents allow you?');
return confirm('Czy rodzice ci pozwolili?');
*/!*
}
```

Is there any difference in the behavior of these two variants?
Czy jest jakakolwiek różnica w zachowaniu tych dwóch wariantów?
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Using a question mark operator `'?'`:
Przy użyciu operatora warunkowego `'?'`:

```js
function checkAge(age) {
return (age > 18) ? true : confirm('Did parents allow you?');
return (age > 18) ? true : confirm('Czy rodzice ci pozwolili?');
}
```

Using OR `||` (the shortest variant):
Używając logicznego OR `||` (krótszy wariant):

```js
function checkAge(age) {
return (age > 18) || confirm('Did parents allow you?');
return (age > 18) || confirm('Czy rodzice ci pozwolili?');
}
```

Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
Zwróć uwagę że nawiasy wokół `age > 18` nie są tutaj wymagane. Są tutaj dla lepszej czytelności.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ importance: 4

---

# Rewrite the function using '?' or '||'
# Przepisz funkcję używając '?' lub '||'

The following function returns `true` if the parameter `age` is greater than `18`.
Następująca funkcja zwraca `true` jeżeli parametr `age` jest większy niż `18`.

Otherwise it asks for a confirmation and returns its result.
W przeciwnym razie prosi o potwierdzenie i zwraca wynik.

```js
function checkAge(age) {
if (age > 18) {
return true;
} else {
return confirm('Did parents allow you?');
return confirm('Czy rodzice ci pozwolili?');
}
}
```

Rewrite it, to perform the same, but without `if`, in a single line.
Przepisz ją, aby zachowywała się tak samo, ale bez `if`, w żadnej z lini.

Make two variants of `checkAge`:
Stwórz dwa warianty `checkAge`:

1. Using a question mark operator `?`
2. Using OR `||`
1. Przy użyciu operatora warunkowego `?`
2. Używając logicznego OR `||`
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`:
Rozwiązanie z wykorzystaniem `if`:

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

A solution with a question mark operator `'?'`:
Rozwiązanie z wykorzystaniem operatora warunkowego `'?'`:

```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. W przypadku równości `a == b` nie ma znaczenia co zostanie zwrócone.
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)
# Funkcja min(a, b)

Write a function `min(a,b)` which returns the least of two numbers `a` and `b`.
Napisz funkcję `min(a,b)` która zwraca najmniejszą z dwóch liczb `a` i `b`.

For instance:
Na przykład:

```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(`Potęga z ${n} nie jest wspierana, użyj dodatniej liczby całkowitej`);
} 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)
# Funkcja 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.
Napisz funkcję `pow(x,n)` która zwraca `x` podniesione do potęgi `n`. Lub, innymi słowy, mnoży `x` przez samą siebie `n` razy i zwraca 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)`.
Stwórz stronę internetową która wyświetla okno dialogowe i prosi od podanie `x` oraz `n`, a następnie pokazuje 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. W tym zadaniu funkcja powinna wspierać jedynie naturalne wartości `n`: liczby całkowite od `1` wzwyż.
Loading