renovations

This commit is contained in:
Ilya Kantor 2015-01-14 10:23:45 +03:00
parent c7d4c7e3ff
commit e1948130f6
170 changed files with 1496 additions and 1161 deletions

View file

@ -0,0 +1,15 @@
function Calculator() {
this.read = function() {
this.a = +prompt('a?', 0);
this.b = +prompt('b?', 0);
};
this.sum = function() {
return this.a + this.b;
};
this.mul = function() {
return this.a * this.b;
};
}

View file

@ -0,0 +1,25 @@
sinon.stub(window, "prompt")
prompt.onCall(0).returns("2");
prompt.onCall(1).returns("3");
describe("calculator", function() {
var calculator;
before(function() {
calculator = new Calculator();
calculator.read();
});
it("при вводе 2 и 3 сумма равна 5", function() {
assert.equal( calculator.sum(), 5 );
});
it("при вводе 2 и 3 произведение равно 6", function() {
assert.equal( calculator.mul(), 6 );
});
});
after(function() {
prompt.restore();
});

View file

@ -0,0 +1,27 @@
```js
//+ run demo
function Calculator() {
this.read = function() {
this.a = +prompt('a?', 0);
this.b = +prompt('b?', 0);
};
this.sum = function() {
return this.a + this.b;
};
this.mul = function() {
return this.a * this.b;
};
}
var calculator = new Calculator();
calculator.read();
alert( "Сумма=" + calculator.sum() );
alert( "Произведение=" + calculator.mul() );
```

View file

@ -0,0 +1,22 @@
# Создать Calculator при помощи конструктора
[importance 5]
Напишите *функцию-конструктор* `Calculator`, которая создает объект с двумя методами:
<ul>
<li>Метод `read()` запрашивает два значения при помощи `prompt` и запоминает их в свойствах объекта.</li>
<li>Метод `sum()` возвращает сумму запомненных свойств.</li>
<li>Метод `mul()` возвращает произведение запомненных свойств.</li>
</ul>
Пример использования:
```js
var calculator = new Calculator();
calculator.read();
alert( "Сумма=" + calculator.sum() );
alert( "Произведение=" + calculator.mul() );
```
[demo /]