Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions 1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md
Original file line number Diff line number Diff 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 deletions 1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md
Original file line number Diff line number Diff 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' );
}
```

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

let value = prompt('What is the "official" name of JavaScript?', '');
let hodnota = 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 deletions 1-js/02-first-steps/10-ifelse/2-check-standard/task.md
Original file line number Diff line number Diff 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í konstrukce `if..else` napište kód, který se zeptá: „Jaký je „oficiální“ název JavaScriptu?“
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 deletions 1-js/02-first-steps/10-ifelse/3-sign/solution.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


```js run
let value = prompt('Type a number', 0);
let hodnota = 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 deletions 1-js/02-first-steps/10-ifelse/3-sign/task.md
Original file line number Diff line number Diff 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"]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


```js
let result = (a + b < 4) ? 'Below' : 'Over';
let výsledek = (a + b < 4) ? 'Málo' : 'Hodně';
```

10 changes: 5 additions & 5 deletions 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md
Original file line number Diff line number Diff 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
let result;
let výsledek;

if (a + b < 4) {
result = 'Below';
výsledek = 'Málo';
} else {
result = 'Over';
výsledek = 'Hodně';
}
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@


```js
let message = (login == 'Employee') ? 'Hello' :
(login == 'Director') ? 'Greetings' :
(login == '') ? 'No login' :
let zpráva = (login == 'Zaměstnanec') ? 'Ahoj' :
(login == 'Ředitel') ? 'Dobrý den' :
(login == '') ? 'Není login' :
'';
```

20 changes: 10 additions & 10 deletions 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md
Original file line number Diff line number Diff 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
let message;
let zpráva;

if (login == 'Employee') {
message = 'Hello';
} else if (login == 'Director') {
message = 'Greetings';
if (login == 'Zaměstnanec') {
zpráva = 'Ahoj';
} else if (login == 'Ředitel') {
zpráva = 'Dobrý den';
} else if (login == '') {
message = 'No login';
zpráva = 'Není login';
} else {
message = '';
zpráva = '';
}
```
Loading