up
This commit is contained in:
parent
d7d25f4d8b
commit
20784e7f26
48 changed files with 302 additions and 397 deletions
|
@ -1,25 +1,25 @@
|
|||
sinon.stub(window, "prompt")
|
||||
|
||||
prompt.onCall(0).returns("2");
|
||||
prompt.onCall(1).returns("3");
|
||||
|
||||
describe("calculator", function() {
|
||||
var calculator;
|
||||
let calculator;
|
||||
before(function() {
|
||||
sinon.stub(window, "prompt")
|
||||
|
||||
prompt.onCall(0).returns("2");
|
||||
prompt.onCall(1).returns("3");
|
||||
|
||||
calculator = new Calculator();
|
||||
calculator.read();
|
||||
});
|
||||
|
||||
it("при вводе 2 и 3 сумма равна 5", function() {
|
||||
it("when 2 and 3 are entered, the sum is 5", function() {
|
||||
assert.equal(calculator.sum(), 5);
|
||||
});
|
||||
|
||||
it("при вводе 2 и 3 произведение равно 6", function() {
|
||||
it("when 2 and 3 are entered, the product is 6", function() {
|
||||
assert.equal(calculator.mul(), 6);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
prompt.restore();
|
||||
});
|
||||
});
|
||||
|
||||
after(function() {
|
||||
prompt.restore();
|
||||
});
|
|
@ -17,10 +17,9 @@ function Calculator() {
|
|||
};
|
||||
}
|
||||
|
||||
var calculator = new Calculator();
|
||||
let calculator = new Calculator();
|
||||
calculator.read();
|
||||
|
||||
alert( "Сумма=" + calculator.sum() );
|
||||
alert( "Произведение=" + calculator.mul() );
|
||||
alert( "Sum=" + calculator.sum() );
|
||||
alert( "Mul=" + calculator.mul() );
|
||||
```
|
||||
|
||||
|
|
|
@ -2,23 +2,22 @@ importance: 5
|
|||
|
||||
---
|
||||
|
||||
# Создать Calculator при помощи конструктора
|
||||
# Create new Calculator
|
||||
|
||||
Напишите *функцию-конструктор* `Calculator`, которая создает объект с тремя методами:
|
||||
Create a constructor function `Calculator` that creates objects with 3 methods:
|
||||
|
||||
- Метод `read()` запрашивает два значения при помощи `prompt` и запоминает их в свойствах объекта.
|
||||
- Метод `sum()` возвращает сумму запомненных свойств.
|
||||
- Метод `mul()` возвращает произведение запомненных свойств.
|
||||
- `read()` asks for two values using `prompt` and remembers them in object properties.
|
||||
- `sum()` returns the sum of these properties.
|
||||
- `mul()` returns the multiplication product of these properties.
|
||||
|
||||
Пример использования:
|
||||
For instance:
|
||||
|
||||
```js
|
||||
var calculator = new Calculator();
|
||||
let calculator = new Calculator();
|
||||
calculator.read();
|
||||
|
||||
alert( "Сумма=" + calculator.sum() );
|
||||
alert( "Произведение=" + calculator.mul() );
|
||||
alert( "Sum=" + calculator.sum() );
|
||||
alert( "Mul=" + calculator.mul() );
|
||||
```
|
||||
|
||||
[demo]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue