Skip to content

Commit 8e52e62

Browse files
committed
1-js/06-advanced-functions/06-function-object/2-counter-inc-dec
1 parent f0f287a commit 8e52e62

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function makeCounter() {
22
let count = 0;
33

4-
// ... your code ...
4+
// ... ваш код ...
55
}
66

77
let counter = makeCounter();
88

99
alert( counter() ); // 0
1010
alert( counter() ); // 1
1111

12-
counter.set(10); // set the new count
12+
counter.set(10); // установить новое значение счётчика
1313

1414
alert( counter() ); // 10
1515

16-
counter.decrease(); // decrease the count by 1
16+
counter.decrease(); // уменьшить значение счётчика на 1
1717

18-
alert( counter() ); // 10 (instead of 11)
18+
alert( counter() ); // 10 (вместо 11)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
The solution uses `count` in the local variable, but addition methods are written right into the `counter`. They share the same outer lexical environment and also can access the current `count`.
2+
В решении использована локальная переменная `count`, а методы сложения записаны прямо в `counter`. Они разделяют одно и то же лексическое окружение и также имеют доступ к текущей переменной `count`.

1-js/06-advanced-functions/06-function-object/2-counter-inc-dec/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ importance: 5
22

33
---
44

5-
# Set and decrease for counter
5+
# Set и decrease для счётчика
66

7-
Modify the code of `makeCounter()` so that the counter can also decrease and set the number:
7+
Изменить код `makeCounter()` так чтобы счетчик мог увеличивать и устанавливать значение:
88

9-
- `counter()` should return the next number (as before).
10-
- `counter.set(value)` should set the `count` to `value`.
11-
- `counter.decrease()` should decrease the `count` by 1.
9+
- `counter()` должен вернуть следующее значение (как и раньше).
10+
- `counter.set(value)` должен установить значение `value` в `count`.
11+
- `counter.decrease()` должен увеличить значение `count` на 1.
1212

13-
See the sandbox code for the complete usage example.
13+
Посмотрите код песочницы для полного примера использования.
1414

15-
P.S. You can use either a closure or the function property to keep the current count. Or write both variants.
15+
P.S. Для того чтобы хранить текущее значение счётчика вы можете использовать как замыкание, так и свойство функции. Или написать оба варианта.

0 commit comments

Comments
 (0)