update
This commit is contained in:
parent
962caebbb7
commit
87bf53d076
1825 changed files with 94929 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
[edit src="solution"/]
|
|
@ -0,0 +1,55 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script>
|
||||
function Machine(power) {
|
||||
this._enabled = false;
|
||||
|
||||
this.enable = function() {
|
||||
this._enabled = true;
|
||||
};
|
||||
|
||||
this.disable = function() {
|
||||
this._enabled = false;
|
||||
};
|
||||
}
|
||||
|
||||
function CoffeeMachine(power) {
|
||||
Machine.apply(this, arguments);
|
||||
|
||||
var waterAmount = 0;
|
||||
var timerId;
|
||||
|
||||
this.setWaterAmount = function(amount) {
|
||||
waterAmount = amount;
|
||||
};
|
||||
|
||||
function onReady() {
|
||||
alert('Кофе готов!');
|
||||
}
|
||||
|
||||
var parentDisable = this.disable;
|
||||
this.disable = function() {
|
||||
parentDisable.call(this);
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
|
||||
this.run = function() {
|
||||
if (!this._enabled) {
|
||||
throw new Error("Кофеварка выключена");
|
||||
}
|
||||
timerId = setTimeout(onReady, 1000);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
var coffeeMachine = new CoffeeMachine(10000);
|
||||
coffeeMachine.run();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,16 @@
|
|||
# Останавливать кофеварку при выключении
|
||||
|
||||
[importance 5]
|
||||
|
||||
Когда кофеварку выключают -- текущая варка кофе должна останавливаться.
|
||||
|
||||
Например, следующий код кофе не сварит:
|
||||
|
||||
```js
|
||||
var coffeeMachine = new CoffeeMachine(10000);
|
||||
coffeeMachine.enable();
|
||||
coffeeMachine.run();
|
||||
coffeeMachine.disable(); // остановит работу, ничего не выведет
|
||||
```
|
||||
|
||||
Реализуйте это на основе решения [предыдущей задачи](/task/coffeemachine-fix-run).
|
Loading…
Add table
Add a link
Reference in a new issue