From f87879d33ab6c35f69609a649869efafe4f1430c Mon Sep 17 00:00:00 2001 From: Otmar Onderek Date: Mon, 18 Apr 2022 22:34:39 +0200 Subject: [PATCH 01/16] 1.2.10 --- .../10-ifelse/1-if-zero-string/solution.md | 8 +- .../10-ifelse/1-if-zero-string/task.md | 6 +- .../2-check-standard/ifelse_task2.svg | 2 +- .../2-check-standard/ifelse_task2/index.html | 8 +- .../10-ifelse/2-check-standard/task.md | 6 +- .../10-ifelse/3-sign/solution.md | 6 +- 1-js/02-first-steps/10-ifelse/3-sign/task.md | 12 +- .../5-rewrite-if-question/solution.md | 2 +- .../10-ifelse/5-rewrite-if-question/task.md | 10 +- .../6-rewrite-if-else-question/solution.md | 6 +- .../6-rewrite-if-else-question/task.md | 20 +- 1-js/02-first-steps/10-ifelse/article.md | 214 +++++++++--------- 12 files changed, 149 insertions(+), 151 deletions(-) diff --git a/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md index 51f1d4680..7c8ea0c2b 100644 --- a/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md +++ b/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md @@ -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' ); } ``` diff --git a/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md index 5f16cda85..93d7360d8 100644 --- a/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md +++ b/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md @@ -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' ); } ``` diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg index 47b020aab..fb567c1c1 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg @@ -1 +1 @@ -BeginYou don't know? “ECMAScript”!Right!What's the “official” name of JavaScript?OtherECMAScript \ No newline at end of file +ZačátekVy to nevíte? “ECMAScript”!Správně!What's the "oficiální" název JavaScript?JinéECMAScript \ No newline at end of file diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html index ea9966653..e052025fc 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html @@ -5,12 +5,12 @@ diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md index 4305584fa..b466649a2 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md @@ -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?“ -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) diff --git a/1-js/02-first-steps/10-ifelse/3-sign/solution.md b/1-js/02-first-steps/10-ifelse/3-sign/solution.md index 262a605c2..73e52e887 100644 --- a/1-js/02-first-steps/10-ifelse/3-sign/solution.md +++ b/1-js/02-first-steps/10-ifelse/3-sign/solution.md @@ -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 ); diff --git a/1-js/02-first-steps/10-ifelse/3-sign/task.md b/1-js/02-first-steps/10-ifelse/3-sign/task.md index 0c5d0e008..adff20a06 100644 --- a/1-js/02-first-steps/10-ifelse/3-sign/task.md +++ b/1-js/02-first-steps/10-ifelse/3-sign/task.md @@ -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"] diff --git a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md index ff32354fa..27a69a1ec 100644 --- a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md @@ -1,6 +1,6 @@ ```js -let result = (a + b < 4) ? 'Below' : 'Over'; +let výsledek = (a + b < 4) ? 'Málo' : 'Hodně'; ``` diff --git a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md index 6bdf8453e..e2b51eb0b 100644 --- a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md +++ b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md @@ -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ě'; } ``` diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md index 6d68e29d7..16fe5a3cf 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md @@ -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' : ''; ``` diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md index 4f7d994a2..c9ef7cb15 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md @@ -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 = ''; } ``` diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index 51514062f..ad9d65122 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -1,239 +1,237 @@ -# Conditional branching: if, '?' +# Podmíněné větvení: if, „?“ -Sometimes, we need to perform different actions based on different conditions. +Někdy potřebujeme provést různé akce v závislosti na platnosti různých podmínek. K tomu můžeme použít příkaz `if` a podmíněný operátor `?`, který se také nazývá operátor „otazníku“. -To do that, we can use the `if` statement and the conditional operator `?`, that's also called a "question mark" operator. +## Příkaz „if“ -## The "if" statement +Příkaz `if(...)` vyhodnotí podmínku v závorkách a je-li výsledek `true`, vykoná blok kódu. -The `if(...)` statement evaluates a condition in parentheses and, if the result is `true`, executes a block of code. - -For example: +Příklad: ```js run -let year = prompt('In which year was ECMAScript-2015 specification published?', ''); +let rok = prompt('Ve kterém roce byla publikována specifikace ECMAScript-2015?', ''); *!* -if (year == 2015) alert( 'You are right!' ); +if (rok == 2015) alert( 'Máte pravdu!' ); */!* ``` -In the example above, the condition is a simple equality check (`year == 2015`), but it can be much more complex. +V uvedeném příkladu je podmínkou jednoduchý test rovnosti (`rok == 2015`), ale může být i mnohem složitější. -If we want to execute more than one statement, we have to wrap our code block inside curly braces: +Jestliže chceme vykonat více než jeden příkaz, musíme náš blok kódu uzavřít do složených závorek: ```js -if (year == 2015) { - alert( "That's correct!" ); - alert( "You're so smart!" ); +if (rok == 2015) { + alert( "Správně!" ); + alert( "Vy jste tak chytrý!" ); } ``` -We recommend wrapping your code block with curly braces `{}` every time you use an `if` statement, even if there is only one statement to execute. Doing so improves readability. +Doporučujeme uzavírat blok kódu do složených závorek `{}` vždy, když použijete příkaz `if`, i když má vykonat pouze jeden příkaz. Zlepšuje to čitelnost. -## Boolean conversion +## Konverze na boolean -The `if (…)` statement evaluates the expression in its parentheses and converts the result to a boolean. +Příkaz `if (…)` vyhodnotí výraz v závorkách a převede výsledek na typ boolean. -Let's recall the conversion rules from the chapter : +Zopakujme si pravidla konverze z kapitoly : -- A number `0`, an empty string `""`, `null`, `undefined`, and `NaN` all become `false`. Because of that they are called "falsy" values. -- Other values become `true`, so they are called "truthy". +- Číslo `0`, prázdný řetězec `""`, `null`, `undefined` a `NaN` se převedou na `false`. Proto se jim také říká „nepravdivé“ hodnoty. +- Ostatní hodnoty se převedou na `true`, proto se jim říká „pravdivé“. -So, the code under this condition would never execute: +Kód pod touto podmínkou se tedy nikdy nevykoná: ```js -if (0) { // 0 is falsy +if (0) { // 0 je nepravdivá ... } ``` -...and inside this condition -- it always will: +...a pod touto podmínkou se naopak vykoná vždy: ```js -if (1) { // 1 is truthy +if (1) { // 1 je pravdivá ... } ``` -We can also pass a pre-evaluated boolean value to `if`, like this: +Můžeme také do `if` předat předem vypočtenou hodnotu, například takto: ```js -let cond = (year == 2015); // equality evaluates to true or false +let podmínka = (rok == 2015); // rovnost se vyhodnotí jako true nebo false -if (cond) { +if (podmínka) { ... } ``` -## The "else" clause +## Klauzule „else“ -The `if` statement may contain an optional "else" block. It executes when the condition is falsy. +Příkaz `if` může obsahovat nepovinný blok „else“, který se vykoná, když podmínka je nepravdivá. -For example: +Příklad: ```js run -let year = prompt('In which year was the ECMAScript-2015 specification published?', ''); +let rok = prompt('Ve kterém roce byla publikována specifikace ECMAScript-2015?', ''); -if (year == 2015) { - alert( 'You guessed it right!' ); +if (rok == 2015) { + alert( 'Uhádl jste!' ); } else { - alert( 'How can you be so wrong?' ); // any value except 2015 + alert( 'Jak se můžete takhle zmýlit?' ); // jakákoli jiná hodnota než 2015 } ``` -## Several conditions: "else if" +## Více podmínek za sebou: „else if“ -Sometimes, we'd like to test several variants of a condition. The `else if` clause lets us do that. +Někdy bychom chtěli otestovat několik variant podmínky. To nám umožní klauzule `else if`. -For example: +Příklad: ```js run -let year = prompt('In which year was the ECMAScript-2015 specification published?', ''); +let rok = prompt('Ve kterém roce byla publikována specifikace ECMAScript-2015?', ''); -if (year < 2015) { - alert( 'Too early...' ); -} else if (year > 2015) { - alert( 'Too late' ); +if (rok < 2015) { + alert( 'Příliš brzy...' ); +} else if (rok > 2015) { + alert( 'Příliš pozdě...' ); } else { - alert( 'Exactly!' ); + alert( 'Přesně!' ); } ``` -In the code above, JavaScript first checks `year < 2015`. If that is falsy, it goes to the next condition `year > 2015`. If that is also falsy, it shows the last `alert`. +Ve výše uvedeném kódu JavaScript napřed ověří podmínku `rok < 2015`. Není-li splněna, pokračuje k další podmínce `rok > 2015`. Není-li splněna ani ta, zobrazí poslední `alert`. -There can be more `else if` blocks. The final `else` is optional. +Bloků `else if` může být více. Závěrečné `else` není povinné. -## Conditional operator '?' +## Podmíněný operátor „?“ -Sometimes, we need to assign a variable depending on a condition. +Někdy potřebujeme přiřadit do proměnné různou hodnotu v závislosti na splnění určité podmínky. -For instance: +Příklad: ```js run no-beautify -let accessAllowed; -let age = prompt('How old are you?', ''); +let přístupPovolen; +let věk = prompt('Kolik je vám let?', ''); *!* -if (age > 18) { - accessAllowed = true; +if (věk > 18) { + přístupPovolen = true; } else { - accessAllowed = false; + přístupPovolen = false; } */!* -alert(accessAllowed); +alert(přístupPovolen); ``` -The so-called "conditional" or "question mark" operator lets us do that in a shorter and simpler way. +Provést to kratším a jednodušším způsobem nám umožní tzv. „podmíněný“ operátor neboli operátor „otazníku“. -The operator is represented by a question mark `?`. Sometimes it's called "ternary", because the operator has three operands. It is actually the one and only operator in JavaScript which has that many. +Tento operátor je reprezentován otazníkem `?`. Někdy se nazývá „ternární“, protože má tři operandy. Je to v současnosti jediný operátor v JavaScriptu, který jich má tolik. -The syntax is: +Jeho syntaxe je: ```js -let result = condition ? value1 : value2; +let výsledek = podmínka ? hodnota1 : hodnota2; ``` -The `condition` is evaluated: if it's truthy then `value1` is returned, otherwise -- `value2`. +Vyhodnotí se `podmínka`: je-li splněna, vrátí se `hodnota1`, jinak se vrátí `hodnota2`. -For example: +Příklad: ```js -let accessAllowed = (age > 18) ? true : false; +let přístupPovolen = (věk > 18) ? true : false; ``` -Technically, we can omit the parentheses around `age > 18`. The question mark operator has a low precedence, so it executes after the comparison `>`. +Technicky můžeme závorky kolem `věk > 18` vynechat. Operátor otazníku má nízkou prioritu, a proto se vykoná až po porovnání `>`. -This example will do the same thing as the previous one: +Tento příklad provede totéž jako předchozí: ```js -// the comparison operator "age > 18" executes first anyway -// (no need to wrap it into parentheses) -let accessAllowed = age > 18 ? true : false; +// porovnávací operátor „věk > 18“ se vykoná jako první +// (není třeba jej uzavírat do závorek) +let přístupPovolen = věk > 18 ? true : false; ``` -But parentheses make the code more readable, so we recommend using them. +Závorky však zlepšují čitelnost kódu, a proto je doporučujeme používat. ````smart -In the example above, you can avoid using the question mark operator because the comparison itself returns `true/false`: +Ve výše uvedeném příkladu se můžeme operátoru otazníku úplně vyhnout, protože samo porovnání vrací `true/false`: ```js -// the same -let accessAllowed = age > 18; +// totéž +let přístupPovolen = věk > 18; ``` ```` -## Multiple '?' +## Více „?“ za sebou -A sequence of question mark operators `?` can return a value that depends on more than one condition. +Sekvence několika operátorů otazníku `?` může vrátit hodnotu, která závisí na více než jedné podmínce. -For instance: +Příklad: ```js run -let age = prompt('age?', 18); +let věk = prompt('Věk?', 18); -let message = (age < 3) ? 'Hi, baby!' : - (age < 18) ? 'Hello!' : - (age < 100) ? 'Greetings!' : - 'What an unusual age!'; +let zpráva = (věk < 3) ? 'Nazdar, mimino!' : + (věk < 18) ? 'Ahoj!' : + (věk < 100) ? 'Dobrý den!' : + 'To je ale vysoký věk!'; -alert( message ); +alert( zpráva ); ``` -It may be difficult at first to grasp what's going on. But after a closer look, we can see that it's just an ordinary sequence of tests: +Na první pohled může být obtížné pochopit, o co tady jde. Po bližším prozkoumání však vidíme, že to je jen obyčejná posloupnost testů: -1. The first question mark checks whether `age < 3`. -2. If true -- it returns `'Hi, baby!'`. Otherwise, it continues to the expression after the colon '":"', checking `age < 18`. -3. If that's true -- it returns `'Hello!'`. Otherwise, it continues to the expression after the next colon '":"', checking `age < 100`. -4. If that's true -- it returns `'Greetings!'`. Otherwise, it continues to the expression after the last colon '":"', returning `'What an unusual age!'`. +1. První otazník ověří, zda `věk < 3`. +2. Pokud ano, vrátí `'Nazdar, mimino!'`. Jinak pokračuje výrazem za dvojtečkou `:` a ověří `věk < 18`. +3. Pokud to platí, vrátí `'Ahoj!'`. Jinak pokračuje výrazem za další dvojtečkou `:` a ověří `věk < 100`. +4. Pokud to platí, vrátí `'Dobrý den!'`. Jinak pokračuje výrazem za poslední dvojtečkou `:` a vrátí `'To je ale vysoký věk!'`. -Here's how this looks using `if..else`: +Při použití `if..else` by to vypadalo následovně: ```js -if (age < 3) { - message = 'Hi, baby!'; -} else if (age < 18) { - message = 'Hello!'; -} else if (age < 100) { - message = 'Greetings!'; +if (věk < 3) { + zpráva = 'Nazdar, mimino!'; +} else if (věk < 18) { + zpráva = 'Ahoj!'; +} else if (věk < 100) { + zpráva = 'Dobrý den!'; } else { - message = 'What an unusual age!'; + zpráva = 'To je ale vysoký věk!'; } ``` -## Non-traditional use of '?' +## Netradiční použití „?“ -Sometimes the question mark `?` is used as a replacement for `if`: +Někdy se otazník `?` používá jako náhrada za `if`: ```js run no-beautify -let company = prompt('Which company created JavaScript?', ''); +let firma = prompt('Která firma vytvořila JavaScript?', ''); *!* -(company == 'Netscape') ? - alert('Right!') : alert('Wrong.'); +(firma == 'Netscape') ? + alert('Správně!') : alert('Špatně.'); */!* ``` -Depending on the condition `company == 'Netscape'`, either the first or the second expression after the `?` gets executed and shows an alert. +Podle platnosti podmínky `firma == 'Netscape'` se buď první, nebo druhý výraz za `?` vykoná a zobrazí zprávu. -We don't assign a result to a variable here. Instead, we execute different code depending on the condition. +Zde nepřiřazujeme výsledek žádné proměnné. Místo toho v závislosti na podmínce spouštíme různý kód. -**It's not recommended to use the question mark operator in this way.** +**Nedoporučuje se používat operátor otazníku tímto způsobem.** -The notation is shorter than the equivalent `if` statement, which appeals to some programmers. But it is less readable. +Zápis je sice kratší než odpovídající příkaz `if`, což může na některé programátory zapůsobit, ale je také méně čitelný. -Here is the same code using `if` for comparison: +Zde je stejný kód, který pro porovnání používá `if`: ```js run no-beautify -let company = prompt('Which company created JavaScript?', ''); +let firma = prompt('Která firma vytvořila JavaScript?', ''); *!* -if (company == 'Netscape') { - alert('Right!'); +if (firma == 'Netscape') { + alert('Správně!'); } else { - alert('Wrong.'); + alert('Špatně.'); } */!* ``` -Our eyes scan the code vertically. Code blocks which span several lines are easier to understand than a long, horizontal instruction set. +Naše oči projíždějí kód shora dolů. Bloky kódu, které jsou roztaženy přes několik řádků, pochopíme snadněji než dlouhou vodorovnou řadu instrukcí. -The purpose of the question mark operator `?` is to return one value or another depending on its condition. Please use it for exactly that. Use `if` when you need to execute different branches of code. +Účelem operátoru otazníku `?` je vrátit jednu nebo druhou hodnotu podle platnosti jeho podmínky. Prosíme, používejte jej přesně takto. Když budete potřebovat vykonat různé větve kódu, použijte `if`. From 146f4abd0fa69d3a3b05ec55af597695ecd8c08c Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:59:26 +0200 Subject: [PATCH 02/16] Update 1-js/02-first-steps/10-ifelse/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/article.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index ad9d65122..bf669b2de 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -1,6 +1,8 @@ # Podmíněné větvení: if, „?“ -Někdy potřebujeme provést různé akce v závislosti na platnosti různých podmínek. K tomu můžeme použít příkaz `if` a podmíněný operátor `?`, který se také nazývá operátor „otazníku“. +Někdy potřebujeme provést různé akce v závislosti na platnosti různých podmínek. + +K tomu můžeme použít příkaz `if` a podmíněný operátor `?`, který se také nazývá operátor „otazníku“. ## Příkaz „if“ From 27bb318dfebba65d828d51c70f3a05621126030c Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:59:34 +0200 Subject: [PATCH 03/16] Update 1-js/02-first-steps/10-ifelse/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index bf669b2de..243101adb 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -75,7 +75,7 @@ Příklad: let rok = prompt('Ve kterém roce byla publikována specifikace ECMAScript-2015?', ''); if (rok == 2015) { - alert( 'Uhádl jste!' ); + alert( 'Uhádli jste!' ); } else { alert( 'Jak se můžete takhle zmýlit?' ); // jakákoli jiná hodnota než 2015 } From 0970831032b04a7fe301bc90d15fbaccf186ffcb Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:59:40 +0200 Subject: [PATCH 04/16] Update 1-js/02-first-steps/10-ifelse/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index 243101adb..4f5c2b629 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -95,7 +95,7 @@ if (rok < 2015) { } else if (rok > 2015) { alert( 'Příliš pozdě...' ); } else { - alert( 'Přesně!' ); + alert( 'Správně!' ); } ``` From f102812c7bcce62d7e81ba53084765befbbe87fa Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:59:50 +0200 Subject: [PATCH 05/16] Update 1-js/02-first-steps/10-ifelse/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index 4f5c2b629..e77e010a7 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -99,7 +99,7 @@ if (rok < 2015) { } ``` -Ve výše uvedeném kódu JavaScript napřed ověří podmínku `rok < 2015`. Není-li splněna, pokračuje k další podmínce `rok > 2015`. Není-li splněna ani ta, zobrazí poslední `alert`. +Ve výše uvedeném kódu JavaScript napřed ověří podmínku `rok < 2015`. Není-li splněna, pokračuje k další podmínce `rok > 2015`. Není-li splněna ani ta, zobrazí se poslední `alert`. Bloků `else if` může být více. Závěrečné `else` není povinné. From 927fb913c87e34bc4d1607b980e1391a076acd15 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 21:59:58 +0200 Subject: [PATCH 06/16] Update 1-js/02-first-steps/10-ifelse/article.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/article.md b/1-js/02-first-steps/10-ifelse/article.md index e77e010a7..869bc72b1 100644 --- a/1-js/02-first-steps/10-ifelse/article.md +++ b/1-js/02-first-steps/10-ifelse/article.md @@ -105,7 +105,7 @@ Bloků `else if` může být více. Závěrečné `else` není povinné. ## Podmíněný operátor „?“ -Někdy potřebujeme přiřadit do proměnné různou hodnotu v závislosti na splnění určité podmínky. +Někdy potřebujeme přiřadit do proměnné hodnotu v závislosti na výsledku podmínky. Příklad: From de77bb1e7903613a4019ba3c759acf7961d3aecc Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:00:17 +0200 Subject: [PATCH 07/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md index c9ef7cb15..ce3125c3b 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md @@ -15,7 +15,7 @@ if (login == 'Zaměstnanec') { zpráva = 'Ahoj'; } else if (login == 'Ředitel') { zpráva = 'Dobrý den'; -} else if (login == '') { +} else if (přihlášený == '') { zpráva = 'Není login'; } else { zpráva = ''; From 5015ba80ac90930595230dd7bbc7480604ff8801 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:00:24 +0200 Subject: [PATCH 08/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md index ce3125c3b..d7d3461c8 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md @@ -16,7 +16,7 @@ if (login == 'Zaměstnanec') { } else if (login == 'Ředitel') { zpráva = 'Dobrý den'; } else if (přihlášený == '') { - zpráva = 'Není login'; + zpráva = 'Nikdo není přihlášený'; } else { zpráva = ''; } From 3c2b67aaf6e935833ee8f0bcc430eabb0427946c Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:00:29 +0200 Subject: [PATCH 09/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../10-ifelse/6-rewrite-if-else-question/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md index 16fe5a3cf..b18c3ff1d 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md @@ -1,7 +1,7 @@ ```js -let zpráva = (login == 'Zaměstnanec') ? 'Ahoj' : +let zpráva = (přihlášený == 'Zaměstnanec') ? 'Ahoj' : (login == 'Ředitel') ? 'Dobrý den' : (login == '') ? 'Není login' : ''; From 2c2197bb1666beaaa87842db9960943e1223eebe Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:00:34 +0200 Subject: [PATCH 10/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../10-ifelse/6-rewrite-if-else-question/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md index b18c3ff1d..ae4ac5abd 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md @@ -2,7 +2,7 @@ ```js let zpráva = (přihlášený == 'Zaměstnanec') ? 'Ahoj' : - (login == 'Ředitel') ? 'Dobrý den' : + (přihlášený == 'Ředitel') ? 'Dobrý den' : (login == '') ? 'Není login' : ''; ``` From 61d8bf2cdf9b747cd12713961b7bb8c66bcdcece Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:00:40 +0200 Subject: [PATCH 11/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../10-ifelse/6-rewrite-if-else-question/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md index ae4ac5abd..efc673852 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/solution.md @@ -3,7 +3,7 @@ ```js let zpráva = (přihlášený == 'Zaměstnanec') ? 'Ahoj' : (přihlášený == 'Ředitel') ? 'Dobrý den' : - (login == '') ? 'Není login' : + (přihlášený == '') ? 'Nikdo není přihlášený' : ''; ``` From c27e754e41d04a07035321525b84c6fd650f2819 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:01:02 +0200 Subject: [PATCH 12/16] Update 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md index e2b51eb0b..d6dc9908d 100644 --- a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md +++ b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/task.md @@ -12,6 +12,6 @@ let výsledek; if (a + b < 4) { výsledek = 'Málo'; } else { - výsledek = 'Hodně'; + výsledek = 'Moc'; } ``` From 4f2420d19c3b8d06b916504a0b078c46d56c38db Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:01:35 +0200 Subject: [PATCH 13/16] Update 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- 1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md index 27a69a1ec..80f19e446 100644 --- a/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md +++ b/1-js/02-first-steps/10-ifelse/5-rewrite-if-question/solution.md @@ -1,6 +1,6 @@ ```js -let výsledek = (a + b < 4) ? 'Málo' : 'Hodně'; +let výsledek = (a + b < 4) ? 'Málo' : 'Moc'; ``` From 697abe4956a19f15013433edc2e0311d4a39bc9f Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:01:49 +0200 Subject: [PATCH 14/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md index d7d3461c8..6b834124b 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md @@ -11,7 +11,7 @@ Z důvodu čitelnosti doporučujeme rozdělit kód na více řádků. ```js let zpráva; -if (login == 'Zaměstnanec') { +if (přihlášený == 'Zaměstnanec') { zpráva = 'Ahoj'; } else if (login == 'Ředitel') { zpráva = 'Dobrý den'; From fbee61f9a42027264c33fd285423cf39b8cd815e Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:02:06 +0200 Subject: [PATCH 15/16] Update 1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Pomajbík <60559058+danipoma@users.noreply.github.com> --- .../02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md index 6b834124b..ade76f6af 100644 --- a/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md +++ b/1-js/02-first-steps/10-ifelse/6-rewrite-if-else-question/task.md @@ -13,7 +13,7 @@ let zpráva; if (přihlášený == 'Zaměstnanec') { zpráva = 'Ahoj'; -} else if (login == 'Ředitel') { +} else if (přihlášený == 'Ředitel') { zpráva = 'Dobrý den'; } else if (přihlášený == '') { zpráva = 'Nikdo není přihlášený'; From fa7f7192ddf135bc7369ffeae1a08533a012b868 Mon Sep 17 00:00:00 2001 From: otmon76 <66325539+otmon76@users.noreply.github.com> Date: Sat, 18 Jun 2022 22:35:52 +0200 Subject: [PATCH 16/16] Update task.md --- 1-js/02-first-steps/10-ifelse/2-check-standard/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md index b466649a2..8950ae4fa 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md @@ -4,7 +4,7 @@ importance: 2 # Název JavaScriptu -Pomocí konstrukce `if..else` napište kód, který se zeptá: „Jaký je „oficiální“ název JavaScriptu?“ +Pomocí konstruktu `if..else` napište kód, který se zeptá: „Jaký je „oficiální“ název JavaScriptu?“ Pokud návštěvník zadá „ECMAScript“, vypište „Správně!“, jinak vypište „Vy to nevíte? ECMAScript!“