From 5720ac656a99c421986e1906a122b0f01c9d9387 Mon Sep 17 00:00:00 2001 From: Gogi Date: Mon, 19 Apr 2021 14:01:51 +0300 Subject: [PATCH 1/6] completed js-object-contructor exercise --- JS-object-constructors/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 JS-object-constructors/index.js diff --git a/JS-object-constructors/index.js b/JS-object-constructors/index.js new file mode 100644 index 0000000..5ebf4bf --- /dev/null +++ b/JS-object-constructors/index.js @@ -0,0 +1,17 @@ +function Book(title, author, pages, isRead) { + this.title = title; + this.author = author; + this.pages = pages; + this.isRead = isRead; + this.info = function () { + if (!isRead) { + return `${this.title} by ${this.author}, ${this.pages} pages, not read yet`; + } else { + return `${this.title} by ${this.author}, ${this.pages} pages, has been read`; + } + }; +} + +const myBook = new Book("Harry Potter", "J. K. Rowling", 495, true); + +console.log(myBook.info()); From 63616d968a4c0597cd414abfa97cca17d5194464 Mon Sep 17 00:00:00 2001 From: Gogi Date: Wed, 21 Apr 2021 14:11:10 +0300 Subject: [PATCH 2/6] renamed 1st exercise --- JS-object-constructors/{index.js => book-constructor-exercise.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename JS-object-constructors/{index.js => book-constructor-exercise.js} (100%) diff --git a/JS-object-constructors/index.js b/JS-object-constructors/book-constructor-exercise.js similarity index 100% rename from JS-object-constructors/index.js rename to JS-object-constructors/book-constructor-exercise.js From a3f73826df5c2494ac114008474fdd4cc7409f0b Mon Sep 17 00:00:00 2001 From: Gogi Date: Wed, 21 Apr 2021 14:12:54 +0300 Subject: [PATCH 3/6] created web-banking-assingment.js --- JS-object-constructors/web-banking-assignment.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 JS-object-constructors/web-banking-assignment.js diff --git a/JS-object-constructors/web-banking-assignment.js b/JS-object-constructors/web-banking-assignment.js new file mode 100644 index 0000000..e69de29 From 451dd14da856908018ade97edc97d42a09d5fa23 Mon Sep 17 00:00:00 2001 From: Gogi Date: Wed, 21 Apr 2021 14:29:57 +0300 Subject: [PATCH 4/6] added constructor function + properties --- .../web-banking-assignment.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/JS-object-constructors/web-banking-assignment.js b/JS-object-constructors/web-banking-assignment.js index e69de29..9956858 100644 --- a/JS-object-constructors/web-banking-assignment.js +++ b/JS-object-constructors/web-banking-assignment.js @@ -0,0 +1,42 @@ +// Create a Function constructor that creates Bank Accounts + +// Implement the following prototype methods: + +// Validation rules include: +// 2.2.1. Amount must not be negative number +// 2.2.2. Amount must be of type Number +// 2.2.3. Amount must not exceed current balance + +function Account(fullname) { + this.fullname = fullname; + // Automatically give a new IBAN number to new accounts. (Static property) + this.IBAN = "GR00010003"; + this.balance = 0; + + // 2.1. deposit: will deposit an amount to the current balance + this.deposit = function (amount) { + return console.log(amount); + }; + // 2.2. withdraw: will withdraw an amount from the current balance an return the withdrawn amount + this.withdraw = function (amount) { + return console.log(amount); + }; + // 2.3. getBalance: will return the current balance + this.getBalance = function () { + return console.log(this.balance); + }; +} + +const newAccount = new Account("Kostas Minaidis"); +// New account created for: Kostas Minaidis +// IBAN: GR00010003 + +newAccount.getBalance(); // 0 +newAccount.deposit(100); +newAccount.getBalance(); // 100 +newAccount.withdraw(50); +newAccount.getBalance(); // 50 + +// newAccount.withdraw( 500 ) // Error 'Insufficient balance!' +// newAccount.withdraw( "50" ) // Error 'Invalid amount' +// newAccount.withdraw( -150 ) // Error 'Invalid amount' From d19845c34ec6e4f5cfebeba6d0607651e90fdcc6 Mon Sep 17 00:00:00 2001 From: Gogi Date: Thu, 22 Apr 2021 00:40:37 +0300 Subject: [PATCH 5/6] completed web banking assignment except creating new IBAN for each customer --- .../web-banking-assignment.js | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/JS-object-constructors/web-banking-assignment.js b/JS-object-constructors/web-banking-assignment.js index 9956858..ed2d2c1 100644 --- a/JS-object-constructors/web-banking-assignment.js +++ b/JS-object-constructors/web-banking-assignment.js @@ -1,42 +1,37 @@ -// Create a Function constructor that creates Bank Accounts - -// Implement the following prototype methods: - -// Validation rules include: -// 2.2.1. Amount must not be negative number -// 2.2.2. Amount must be of type Number -// 2.2.3. Amount must not exceed current balance +"use strict"; function Account(fullname) { this.fullname = fullname; - // Automatically give a new IBAN number to new accounts. (Static property) - this.IBAN = "GR00010003"; - this.balance = 0; - // 2.1. deposit: will deposit an amount to the current balance + this.balance = 0; this.deposit = function (amount) { - return console.log(amount); + return this.balance = this.balance + amount; }; - // 2.2. withdraw: will withdraw an amount from the current balance an return the withdrawn amount this.withdraw = function (amount) { - return console.log(amount); + if (typeof amount !== "number" || amount <= 0){ + return "Error 'Invalid amount'" + } + if (amount > this.balance) { + return "Error 'Insufficient balance!'" + } + return this.balance = this.balance - amount; }; - // 2.3. getBalance: will return the current balance this.getBalance = function () { - return console.log(this.balance); + return this.balance; }; } + + const newAccount = new Account("Kostas Minaidis"); // New account created for: Kostas Minaidis // IBAN: GR00010003 -newAccount.getBalance(); // 0 -newAccount.deposit(100); -newAccount.getBalance(); // 100 -newAccount.withdraw(50); -newAccount.getBalance(); // 50 +console.log({ newAccount }); -// newAccount.withdraw( 500 ) // Error 'Insufficient balance!' -// newAccount.withdraw( "50" ) // Error 'Invalid amount' -// newAccount.withdraw( -150 ) // Error 'Invalid amount' +console.log( newAccount.getBalance() ); // 0 +newAccount.deposit(100); +console.log( newAccount.getBalance() ); // 100 +console.log(newAccount.withdraw(50)); +// newAccount.withdraw(50); +console.log( newAccount.getBalance() ); // 50 From 4abcea33da16b9ce69d6762b1e7cfc05b99fc3d1 Mon Sep 17 00:00:00 2001 From: Gogi Date: Thu, 22 Apr 2021 22:31:05 +0300 Subject: [PATCH 6/6] completed web banking assignment --- JS-object-constructors/web-banking-assignment.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/JS-object-constructors/web-banking-assignment.js b/JS-object-constructors/web-banking-assignment.js index ed2d2c1..e8c0ddb 100644 --- a/JS-object-constructors/web-banking-assignment.js +++ b/JS-object-constructors/web-banking-assignment.js @@ -2,7 +2,8 @@ function Account(fullname) { this.fullname = fullname; - + Account.IBAN++; + this.IBAN = "GR000" + Account.IBAN; this.balance = 0; this.deposit = function (amount) { return this.balance = this.balance + amount; @@ -21,17 +22,14 @@ function Account(fullname) { }; } +Account.IBAN = 10003; const newAccount = new Account("Kostas Minaidis"); -// New account created for: Kostas Minaidis -// IBAN: GR00010003 -console.log({ newAccount }); -console.log( newAccount.getBalance() ); // 0 +newAccount.getBalance(); // 0 newAccount.deposit(100); -console.log( newAccount.getBalance() ); // 100 -console.log(newAccount.withdraw(50)); -// newAccount.withdraw(50); -console.log( newAccount.getBalance() ); // 50 +newAccount.getBalance(); // 100 +newAccount.withdraw(50); +newAccount.getBalance(); // 50