update
This commit is contained in:
parent
962caebbb7
commit
87bf53d076
1825 changed files with 94929 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
|||
var calculator = {
|
||||
sum: function() {
|
||||
return this.a + this.b;
|
||||
},
|
||||
|
||||
mul: function() {
|
||||
return this.a * this.b;
|
||||
},
|
||||
|
||||
read: function() {
|
||||
this.a = +prompt('a?', 0);
|
||||
this.b = +prompt('b?', 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
sinon.stub(window, "prompt");
|
||||
|
||||
prompt.onCall(0).returns("2");
|
||||
prompt.onCall(1).returns("3");
|
||||
|
||||
describe("calculator", function() {
|
||||
before(function() {
|
||||
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();
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
|
||||
```js
|
||||
//+ run demo
|
||||
var calculator = {
|
||||
sum: function() {
|
||||
return this.a + this.b;
|
||||
},
|
||||
|
||||
mul: function() {
|
||||
return this.a * this.b;
|
||||
},
|
||||
|
||||
read: function() {
|
||||
this.a = +prompt('a?', 0);
|
||||
this.b = +prompt('b?', 0);
|
||||
}
|
||||
}
|
||||
|
||||
calculator.read();
|
||||
alert( calculator.sum() );
|
||||
alert( calculator.mul() );
|
||||
```
|
||||
|
22
1-js/6-objects-more/1-object-methods/7-calculator/task.md
Normal file
22
1-js/6-objects-more/1-object-methods/7-calculator/task.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Создайте калькулятор
|
||||
|
||||
[importance 5]
|
||||
|
||||
Создайте объект `calculator` с тремя методами:
|
||||
<ul>
|
||||
<li>`read()` запрашивает `prompt` два значения и сохраняет их как свойства объекта</li>
|
||||
<li>`sum()` возвращает сумму этих двух значений</li>
|
||||
<li>`mul()` возвращает произведение этих двух значений</li>
|
||||
</ul>
|
||||
|
||||
```js
|
||||
var calculator = {
|
||||
... ваш код...
|
||||
}
|
||||
|
||||
calculator.read();
|
||||
alert( calculator.sum() );
|
||||
alert( calculator.mul() );
|
||||
```
|
||||
|
||||
[demo /]
|
Loading…
Add table
Add a link
Reference in a new issue