forked from coach-stephanie/te2018grade9term1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.js
More file actions
82 lines (68 loc) · 3.38 KB
/
methods.js
File metadata and controls
82 lines (68 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// **** Bank Account Object ****
// This object represents a bank account
// and includes properties of owner, withdrawalLimit, balance, and bankName
// it also has three methods that you will have to create!
let bankAccount = {
owner: undefined,
withdrawalLimit: 50,
balance: 100,
bankName: 'Chase Bank',
deposit: function(money) {
let newBalance = this.balance + money;
this.balance = this.balance + money;
console.log(`depostie success! $${this.balance}`);
},
withdraw: function(amount) {
if((amount <= this.withdrawalLimit && amount <= this.balance) && (amount > 0)){
let newBalance = this.balance - amount;
this.balance = newBalance;
}
},
createGreeting: function() {
let greeting = "Hi, "+this.owner+"! welcome to "+this.bankName+"!";
return greeting;
}
};
// **** Problem 1: Greet the User ****
// Update the property 'owner' to be your name
// Then fill in the createGreeting method so that it will RETURN a greeting,
// including the bank name and owner name
// Our tests will then print that returned greeting to the terminal
bankAccount.owner = "Devauntea";
// **** Problem 1 Tests ****
console.log('**** Problem 1 Tests ****');
console.log(`${typeof bankAccount.owner}... should be string`);
console.log(`${bankAccount.createGreeting()}... should include a greeting, ${bankAccount.owner}, and ${bankAccount.bankName}`);
// **** Problem 2: Deposit Monies ****
// Then fill in the deposit method
// It needs to take an argument to add to the bankAccount's balance
// and print a success message including the amount deposited
// **** Problem 2 Tests ****
console.log('\n\n**** Problem 2 Tests ****');
console.log(`Before depositing any money our balance was ${bankAccount.balance}`);
bankAccount.deposit(50);
console.log('Just ran the deposit... did it print a success message?');
console.log(`After the deposit our balance should be 150.... our current balance is ${bankAccount.balance}`);
// **** Problem 3: Withdraw Monies ****
// Then fill in the withdrawal method
// This one requires a bit more logic than the first two!
// This method will take an argument to withdraw from the bank Account
// If it doesn't exceed the withdrawalLimit and the balance and is above 0, remove the amount and print a success message
// Otherwise do not remove the amount and print a failure messages
// **** Problem 3 Tests ****
console.log('\n\n**** Problem 3 Tests ****');
let priorBalance = bankAccount.balance;
console.log(`Before withdrawing any money our balance was ${priorBalance}`);
bankAccount.withdraw(120);
console.log('Just ran the withdrawal but with too high an amount... did it print a failure message?');
console.log(`The balance should still be the same as before. \nPrior Balance: ${priorBalance}\nCurrent Balance: ${bankAccount.balance}`)
bankAccount.withdraw(20);
console.log('Just ran a successful withdrawal of $20. Was a success message printed?');
console.log(`The balance should have been decreased by $20. \nPrior Balance: ${priorBalance}\nCurrent Balance: ${bankAccount.balance}`)
// **** Problem 4: Object Methods ****
// Write code that represents any object you like. Your object should have at
// least four properties and four methods. At least two of your methods should
// utilize the "this" keyword to refer to properties, or call other methods,
// owned by the object.
// Test all of your object's methods below.
console.log('\n\n**** Problem 4 Tests ****');