From 78ebe07977ee33d8300f3666b816689d83b8d79d Mon Sep 17 00:00:00 2001 From: mhrooz Date: Mon, 3 Jun 2024 12:16:54 +0200 Subject: [PATCH] constructor is a function --- 4.5constructor/index.html | 21 +++++++++++++++++++++ 4.5constructor/t2.js | 12 ++++++++++++ 4.5constructor/t3.js | 11 +++++++++++ 3 files changed, 44 insertions(+) create mode 100644 4.5constructor/index.html create mode 100644 4.5constructor/t2.js create mode 100644 4.5constructor/t3.js 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