Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions JS-object-constructors/book-constructor-exercise.js
Original file line number Diff line number Diff line change
@@ -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());
35 changes: 35 additions & 0 deletions JS-object-constructors/web-banking-assignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

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;
};
this.withdraw = function (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;
};
this.getBalance = function () {
return this.balance;
};
}

Account.IBAN = 10003;


const newAccount = new Account("Kostas Minaidis");


newAccount.getBalance(); // 0
newAccount.deposit(100);
newAccount.getBalance(); // 100
newAccount.withdraw(50);
newAccount.getBalance(); // 50