diff --git a/4.5constructor/index.html b/4.5constructor/index.html new file mode 100644 index 0000000..96626fc --- /dev/null +++ b/4.5constructor/index.html @@ -0,0 +1,21 @@ + + +
+ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/4.5constructor/t2.js b/4.5constructor/t2.js new file mode 100644 index 0000000..ca20f44 --- /dev/null +++ b/4.5constructor/t2.js @@ -0,0 +1,12 @@ +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; + }; +} \ No newline at end of file diff --git a/4.5constructor/t3.js b/4.5constructor/t3.js new file mode 100644 index 0000000..426770e --- /dev/null +++ b/4.5constructor/t3.js @@ -0,0 +1,11 @@ +function Accumulator(startingValue){ + this.value = startingValue; + this.read = function(){ + new_value = +prompt("value?", 0); + this.value += new_value; + } +} + +let accumulator = new Accumulator(1); +accumulator.read(); +alert(accumulator.value); \ No newline at end of file