Skip to content

Commit 04d0e3f

Browse files
committed
up
1 parent db39a8b commit 04d0e3f

11 files changed

Lines changed: 51 additions & 66 deletions

File tree

1-js/2-first-steps/12-ifelse/2-check-standardifelse_task2/index.html

Lines changed: 0 additions & 18 deletions
This file was deleted.

1-js/2-first-steps/12-ifelse/3-sign/if_sign/index.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
<!DOCTYPE html>
22
<html>
33

4-
<head>
5-
<meta charset="utf-8">
6-
</head>
7-
84
<body>
95

106
<script>
11-
var value = prompt('Введите число', 0);
7+
var value = prompt('Type a number', 0);
128

139
if (value > 0) {
1410
alert(1);

1-js/2-first-steps/12-ifelse/3-sign/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```js
44
//+ run
5-
var value = prompt('Введите число', 0);
5+
var value = prompt('Type a number', 0);
66

77
if (value > 0) {
88
alert( 1 );
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# Получить знак числа
1+
# Show the sign
22

33
[importance 2]
44

5-
Используя конструкцию `if..else`, напишите код, который получает значение `prompt`, а затем выводит `alert`:
5+
Using `if..else`, write the code which gets a number via `prompt` and then shows in `alert`:
6+
67
<ul>
7-
<li>`1`, если значение больше нуля,</li>
8-
<li>`-1`, если значение меньше нуля,</li>
9-
<li>`0`, если значение равно нулю.</li>
8+
<li>`1`, if the value is greater than zero,</li>
9+
<li>`-1`, if less than zero,</li>
10+
<li>`0`, if equals zero.</li>
1011
</ul>
1112

13+
In this task we assume that the input is always a number.
14+
1215
[demo src="if_sign"]

1-js/2-first-steps/12-ifelse/4-check-login/solution.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22

33
```js
44
//+ run demo
5-
var userName = prompt('Кто пришёл?', '');
5+
var userName = prompt('Who's there?', '');
66
7-
if (userName == 'Админ') {
7+
if (userName == 'Admin') {
88
9-
var pass = prompt('Пароль?', '');
9+
var pass = prompt('Password?', '');
1010
11-
if (pass == 'Чёрный Властелин') {
12-
alert( 'Добро пожаловать!' );
13-
} else if (pass == null) { // (*)
14-
alert( 'Вход отменён' );
11+
if (pass == 'TheMaster') {
12+
alert( 'Welcome!' );
13+
} else if (pass == null || pass == '') { // (*)
14+
alert( 'Canceled.' );
1515
} else {
16-
alert( 'Пароль неверен' );
16+
alert( 'Wrong password' );
1717
}
1818
19-
} else if (userName == null) { // (**)
20-
alert( 'Вход отменён' );
19+
} else if (userName == null || userName == '') { // (**)
20+
21+
alert( 'Canceled' );
2122
2223
} else {
2324
24-
alert( 'Я вас не знаю' );
25+
alert( "I don't know you" );
2526
2627
}
2728
```
2829
29-
Обратите внимание на проверку `if` в строках `(*)` и `(**)`. Везде, кроме Safari, нажатие "Отмена" возвращает `null`, а вот Safari возвращает при отмене пустую строку, поэтому в браузере Safari можно было бы добавить дополнительную проверку на неё.
30-
31-
Впрочем, такое поведение Safari является некорректным, надеемся, что скоро его исправят.
30+
Please note the `if` check in lines `(*)` and `(**)`. Every browser except Safari returns `null` when the input is canceled, and Safari returns an empty string. So we must treat them same for compatibility.
3231
33-
Кроме того, обратите внимание на дополнительные вертикальные отступы внутри `if`. Они не обязательны, но полезны для лучшей читаемости кода.
32+
Also note the vertical indents inside the `if` blocks. They are technically not required, but make the code more readable.
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
# Проверка логина
1+
# Check the login
22

33
[importance 3]
44

5-
Напишите код, который будет спрашивать логин (`prompt`).
5+
Write the code which asks for a login with `prompt`.
66

7-
Если посетитель вводит "Админ", то спрашивать пароль, если нажал отмена (escape) -- выводить "Вход отменён", если вводит что-то другое -- "Я вас не знаю".
7+
If the visitor enters `"Admin"`, then `prompt` for a password, if the input is an empty line or [key Esc] -- show "Canceled.", if it's another string -- then show "I don't know you".
88

9-
Пароль проверять так. Если введён пароль "Чёрный Властелин", то выводить "Добро пожаловать!", иначе -- "Пароль неверен", при отмене -- "Вход отменён".
9+
The password is checked as follows:
10+
<ul>
11+
<li>If it equals "TheMaster", then show "Welcome!",</li>
12+
<li>Another string -- show "Wrong password",</li>
13+
<li>For an empty string or cancelled input, show "Canceled."</li>
14+
</ul>
1015

11-
Блок-схема:
16+
The schema:
1217

1318
<img src="ifelse_task.png">
1419

15-
Для решения используйте вложенные блоки `if`. Обращайте внимание на стиль и читаемость кода.
20+
Please use nested `if` blocks. Mind the overall readability of the code.
1621

1722
[demo /]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

33
```js
4-
result = (a + b < 4) ? 'Мало' : 'Много';
4+
result = (a + b < 4) ? 'Below' : 'Over';
55
```
66

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Перепишите 'if' в '?'
1+
# Rewrite 'if' into '?'
22

33
[importance 5]
44

5-
Перепишите `if` с использованием оператора `'?'`:
5+
Rewrite this `if` using the ternary operator `'?'`:
66

77
```js
88
if (a + b < 4) {
9-
result = 'Мало';
9+
result = 'Below';
1010
} else {
11-
result = 'Много';
11+
result = 'Over';
1212
}
1313
```
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22

33
```js
4-
var message = (login == 'Вася') ? 'Привет' :
5-
(login == 'Директор') ? 'Здравствуйте' :
6-
(login == '') ? 'Нет логина' :
4+
var message = (login == 'Employee') ? 'Hello' :
5+
(login == 'Director') ? 'Greetings' :
6+
(login == '') ? 'No login' :
77
'';
88
```
99

1-js/2-first-steps/12-ifelse/6-rewrite-if-else-question/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Перепишите 'if..else' в '?'
1+
# Rewrite 'if..else' into '?'
22

33
[importance 5]
44

5-
Перепишите `if..else` с использованием нескольких операторов `'?'`.
5+
Rewrite `if..else` using multiple ternary operators `'?'`.
66

7-
Для читаемости -- оформляйте код в несколько строк.
7+
For readability, please let the code span several lines.
88

99
```js
1010
var message;
1111

12-
if (login == 'Вася') {
13-
message = 'Привет';
14-
} else if (login == 'Директор') {
15-
message = 'Здравствуйте';
12+
if (login == 'Employee') {
13+
message = 'Hello';
14+
} else if (login == 'Director') {
15+
message = 'Greetings';
1616
} else if (login == '') {
17-
message = 'Нет логина';
17+
message = 'No login';
1818
} else {
1919
message = '';
2020
}

0 commit comments

Comments
 (0)