Skip to content

Commit 73cebe1

Browse files
committed
All done except stretch goals
1 parent ed3ebea commit 73cebe1

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed

src/class.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// DONE
12
// Part 1
23
// Create a class called User using the ES6 class keyword.
34
// The constructor of the class should have a parameter called `options`.
@@ -8,6 +9,15 @@
89
// Return true if the potential password matches the `password` property. Otherwise return false.
910

1011
// code here
12+
class User {
13+
constructor(options) {
14+
this.email = options.email;
15+
this.password = options.password;
16+
}
17+
comparePasswords(potentialPassword) {
18+
return this.password === potentialPassword;
19+
}
20+
}
1121

1222
// Part 2
1323
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
@@ -20,7 +30,24 @@
2030
// property set on the Cat instance.
2131

2232
// code here
33+
class Animal {
34+
constructor(options) {
35+
this.age = options.age;
36+
}
37+
growOlder() {
38+
return this.age + 1;
39+
}
40+
}
2341

42+
class Cat extends Animal {
43+
constructor(options) {
44+
super(options);
45+
this.name = options.name;
46+
}
47+
meow() {
48+
return `${this.name} meowed!`;
49+
}
50+
}
2451
/* eslint-disable no-undef */
2552

2653
module.exports = {

src/prototype.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// DONE
12
/*
23
Object oriented design is commonly used in video games. For this part of the assignment
34
you will be implementing several classes with their correct inheritance heirarchy.
@@ -48,6 +49,37 @@
4849
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
4950
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
5051
*/
52+
// GameObject
53+
function GameObject(attributes) {
54+
this.createdAt = attributes.createdAt;
55+
this.dimensions = attributes.dimensions;
56+
}
57+
GameObject.prototype.destroy = function () {
58+
return 'Game object was removed from the game.';
59+
};
60+
61+
// NPC
62+
function NPC(npcAttributes) {
63+
this.hp = npcAttributes.hp;
64+
this.name = npcAttributes.name;
65+
GameObject.call(this, npcAttributes);
66+
}
67+
NPC.prototype = Object.create(GameObject.prototype);
68+
NPC.prototype.takeDamage = function () {
69+
return `${this.name} took damage.`;
70+
};
71+
72+
// Humanoid
73+
function Humanoid(humAttributes) {
74+
NPC.call(this, humAttributes);
75+
this.faction = humAttributes.faction;
76+
this.weapons = humAttributes.weapons;
77+
this.language = humAttributes.language;
78+
}
79+
Humanoid.prototype = Object.create(NPC.prototype);
80+
Humanoid.prototype.greet = function () {
81+
return `${this.name} offers a greeting in ${this.language}.`;
82+
};
5183

5284
/* eslint-disable no-undef */
5385

src/recursion.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// DONE - stretch goal
2+
13
// Complete the following functions.
24

35
const nFibonacci = (n) => {

src/this.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Check again for last part**
2+
13
// Follow the instructions and fill in the blank sections.
24
// There are no tests for this file.
35
// To verify your code works you can run this file using `node this.js` while in the `/src` folder
@@ -7,18 +9,24 @@
79
class User {
810
constructor(options) {
911
// set a username and password property on the user object that is created
12+
this.username = options.username;
13+
this.password = options.password;
1014
}
1115
// create a method on the User class called `checkPassword`
1216
// this method should take in a string and compare it to the object's password property
1317
// return `true` if they match, otherwise return `false`
18+
checkPassword(passwordToCompare) {
19+
return this.password === passwordToCompare;
20+
}
1421
}
15-
1622
const me = new User({
1723
username: 'LambdaSchool',
1824
password: 'correcthorsebatterystaple',
1925
});
2026

2127
const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`
28+
console.log(result);
29+
2230

2331
/* part 2 */
2432

@@ -27,13 +35,19 @@ const checkPassword = function comparePasswords(passwordToCompare) {
2735
// use `this` to access the object's `password` property.
2836
// do not modify this function's parameters
2937
// note that we use the `function` keyword and not `=>`
38+
return this.password === passwordToCompare;
3039
};
3140

3241
// invoke `checkPassword` on `me` by explicitly setting the `this` context
3342
// use .call, .apply, and .bind
3443

3544
// .call
45+
checkPassword.call(me, 'correcthorsebatterystaple');
3646

3747
// .apply
48+
checkPassword.apply(me, 'correcthorsebatterystaple');
3849

3950
// .bind
51+
const boundedCheck = checkPassword.bind(me);
52+
boundedCheck('correcthorsebatterystaple');
53+

yarn-error.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Arguments:
2-
D:\Program Files\nodejs\node.exe C:\Users\mykim\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js test recursion
2+
D:\Program Files\nodejs\node.exe C:\Users\mykim\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js test class
33

44
PATH:
55
C:\Users\mykim\bin;D:\Program Files\Git\mingw64\bin;D:\Program Files\Git\usr\local\bin;D:\Program Files\Git\usr\bin;D:\Program Files\Git\usr\bin;D:\Program Files\Git\mingw64\bin;D:\Program Files\Git\usr\bin;C:\Users\mykim\bin;C:\ProgramData\Oracle\Java\javapath;D:\Program Files (x86)\Intel\iCLS Client;D:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;D:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;D:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;D:\Program Files\Intel\Intel(R) Management Engine Components\DAL;D:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;D:\Program Files\Intel\Intel(R) Management Engine Components\IPT;D:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Program Files\Java\jre1.8.0_161\bin;D:\Program Files\nodejs;C:\Users\mykim\AppData\Local\Microsoft\WindowsApps;D:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;D:\Program Files\Bandizip;C:\Users\mykim\AppData\Local\atom\bin;D:\Program Files\Microsoft VS Code\bin;C:\Users\mykim\AppData\Roaming\npm;D:\Program Files\Git\usr\bin\vendor_perl;D:\Program Files\Git\usr\bin\core_perl
@@ -55,7 +55,7 @@ Trace:
5555
Error: Command failed.
5656
Exit code: 1
5757
Command: C:\Windows\system32\cmd.exe
58-
Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose recursion
58+
Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose class
5959
Directory: C:\Users\mykim\Desktop\lambda_practice\JavaScript-II
6060
Output:
6161

0 commit comments

Comments
 (0)