Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Functions#85

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deivuss331 merged 7 commits intojavascript-tutorial:masterfromdyrpit:14-function-basics
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
No difference.
Nie ma żadnej różnicy.
View file
Open in desktop
Original file line numberDiff line numberDiff 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
functioncheckAge(age) {
Expand All@@ -15,13 +15,13 @@ function checkAge(age) {
*!*
}else {
// ...
returnconfirm('Did parents allow you?');
returnconfirm('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
functioncheckAge(age) {
Expand All@@ -30,9 +30,9 @@ function checkAge(age) {
}
*!*
// ...
returnconfirm('Did parents allow you?');
returnconfirm('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?
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
Using a question mark operator`'?'`:
Przy użyciu operatora warunkowego`'?'`:

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

UsingOR`||` (the shortest variant):
Używając logicznegoOR`||` (krótszy wariant):

```js
functioncheckAge(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.
View file
Open in desktop
Original file line numberDiff line numberDiff 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
functioncheckAge(age) {
if (age>18) {
returntrue;
}else {
returnconfirm('Did parents allow you?');
returnconfirm('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 deletions1-js/02-first-steps/14-function-basics/3-min/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
A solution using`if`:
Rozwiązanie z wykorzystaniem`if`:

```js
functionmin(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
functionmin(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 deletions1-js/02-first-steps/14-function-basics/3-min/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletions1-js/02-first-steps/14-function-basics/4-pow/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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

[8]ページ先頭

©2009-2025 Movatter.jp