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

Conditional branching: if, '?'#76

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
danipoma merged 16 commits intojavascript-tutorial:masterfromotmon76:1.2.10
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
f87879d
1.2.10
otmon76Apr 18, 2022
146f4ab
Update 1-js/02-first-steps/10-ifelse/article.md
otmon76Jun 18, 2022
27bb318
Update 1-js/02-first-steps/10-ifelse/article.md
otmon76Jun 18, 2022
0970831
Update 1-js/02-first-steps/10-ifelse/article.md
otmon76Jun 18, 2022
f102812
Update 1-js/02-first-steps/10-ifelse/article.md
otmon76Jun 18, 2022
927fb91
Update 1-js/02-first-steps/10-ifelse/article.md
otmon76Jun 18, 2022
de77bb1
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
otmon76Jun 18, 2022
5015ba8
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
otmon76Jun 18, 2022
3c2b67a
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solut…
otmon76Jun 18, 2022
2c2197b
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solut…
otmon76Jun 18, 2022
61d8bf2
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solut…
otmon76Jun 18, 2022
c27e754
Update 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md
otmon76Jun 18, 2022
4f2420d
Update 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md
otmon76Jun 18, 2022
697abe4
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
otmon76Jun 18, 2022
fbee61f
Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
otmon76Jun 18, 2022
fa7f719
Update task.md
otmon76Jun 18, 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
**Yes, it will.**
**Ano, zobrazí.**

Any string except an empty one (and `"0"`is not empty) becomes `true` in the logical context.
Každý řetězec kromě prázdného (a `"0"`není prázdný řetězec) se v logickém kontextu převede na `true`.

We can run and check:
Můžeme si to spustit a uvidíme:

```js run
if ("0") {
alert( 'Hello' );
alert( 'Ahoj' );
}
```

6 changes: 3 additions & 3 deletions1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,13 +2,13 @@ importance: 5

---

# if (a string with zero)
# if (řetězec s nulou)

Will`alert` be shown?
Zobrazí se`alert`?

```js
if ("0") {
alert( 'Hello' );
alert( 'Ahoj' );
}
```

View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,12 +5,12 @@
<script>
'use strict';

letvalue = prompt('What is the "official" name of JavaScript?', '');
lethodnota = prompt('Jaký je „oficiální“ název JavaScriptu?', '');

if (value == 'ECMAScript') {
alert('Right!');
if (hodnota == 'ECMAScript') {
alert('Správně!');
} else {
alert("You don't know? ECMAScript!");
alert("Vy to nevíte? ECMAScript!");
}
</script>

Expand Down
6 changes: 3 additions & 3 deletions1-js/02-first-steps/10-ifelse/2-check-standard/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,11 @@ importance: 2

---

#The name of JavaScript
#Název JavaScriptu

Using the `if..else`construct, write the code which asks: 'What is the "official" name of JavaScript?'
Pomocí konstruktu `if..else`napište kód, který se zeptá: „Jaký je „oficiální“ název JavaScriptu?“

If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "You don't know? ECMAScript!"
Pokud návštěvník zadá „ECMAScript“, vypište „Správně!“, jinak vypište „Vy to nevíte? ECMAScript!

![](ifelse_task2.svg)

Expand Down
6 changes: 3 additions & 3 deletions1-js/02-first-steps/10-ifelse/3-sign/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@


```js run
letvalue = prompt('Type a number', 0);
lethodnota = prompt('Zadejte číslo', 0);

if (value > 0) {
if (hodnota > 0) {
alert( 1 );
} else if (value < 0) {
} else if (hodnota < 0) {
alert( -1 );
} else {
alert( 0 );
Expand Down
12 changes: 6 additions & 6 deletions1-js/02-first-steps/10-ifelse/3-sign/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,14 +2,14 @@ importance: 2

---

#Show the sign
#Zobrazte znaménko

Using `if..else`, write the code which gets a number via`prompt`and then shows in`alert`:
Pomocí `if..else` napište kód, který načte číslo pomocí`prompt`a pak pomocí`alert` zobrazí:

- `1`,if the value is greater than zero,
- `-1`,if less than zero,
- `0`,if equals zero.
- `1`,je-li toto číslo větší než nula,
- `-1`,je-li menší než nula,
- `0`,je-li rovno nule.

In this task we assume that the input is always a number.
V tomto cvičení předpokládáme, že vstupem je vždy číslo.

[demo src="if_sign"]
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@


```js
letresult = (a + b < 4) ? 'Below' : 'Over';
letvýsledek = (a + b < 4) ? 'Málo' : 'Moc';
```

10 changes: 5 additions & 5 deletions1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,16 +2,16 @@ importance: 5

---

#Rewrite 'if' into '?'
#Přepište „if“ na „?“

Rewrite this`if`using the conditional operator `'?'`:
Přepište tento příkaz`if`pomocí podmíněného operátoru `'?'`:

```js
letresult;
letvýsledek;

if (a + b < 4) {
result = 'Below';
výsledek = 'Málo';
} else {
result = 'Over';
výsledek = 'Moc';
}
```
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@


```js
letmessage = (login == 'Employee') ? 'Hello' :
(login == 'Director') ? 'Greetings' :
(login == '') ? 'No login' :
letzpráva = (přihlášený == 'Zaměstnanec') ? 'Ahoj' :
(přihlášený == 'Ředitel') ? 'Dobrý den' :
(přihlášený == '') ? 'Nikdo není přihlášený' :
'';
```

View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,22 +2,22 @@ importance: 5

---

#Rewrite 'if..else' into '?'
#Přepište „if..else“ na „?“

Rewrite `if..else`using multiple ternary operators `'?'`.
Přepište `if..else`pomocí několika ternárních operátorů `'?'`.

For readability, it's recommended to split the code into multiple lines.
Z důvodu čitelnosti doporučujeme rozdělit kód na více řádků.

```js
letmessage;
letzpráva;

if (login == 'Employee') {
message = 'Hello';
} else if (login == 'Director') {
message = 'Greetings';
} else if (login == '') {
message = 'No login';
if (přihlášený == 'Zaměstnanec') {
zpráva = 'Ahoj';
} else if (přihlášený == 'Ředitel') {
zpráva = 'Dobrý den';
} else if (přihlášený == '') {
zpráva = 'Nikdo není přihlášený';
} else {
message = '';
zpráva = '';
}
```
Loading

[8]ページ先頭

©2009-2025 Movatter.jp