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
32 changes: 31 additions & 1 deletion src/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@
// Add a method called `comparePasswords`. `comparePasswords` should have a parameter
// for a potential password that will be compared to the `password` property.
// Return true if the potential password matches the `password` property. Otherwise return false.

// code here
class User {
constructor(options) {
this.email = options.email;
this.password = options.password;
}
comparePassowrds(param) {
if (param === this.password) {
return true;
}
else {
return false;
}
}
};

// Part 2
// Create a class called `Animal` and a class called `Cat` using ES6 classes.
Expand All @@ -20,6 +33,23 @@
// property set on the Cat instance.

// code here
class Animal {
constructor(options) {
this.age = options.age;
}
growOlder() {
return ++this.age;
}
};
class Cat extends Animal {
constructor(options) {
super(options);
this.name = options.name;
}
meow() {
return `${this.name} meowed!`;
}
};

/* eslint-disable no-undef */

Expand Down
54 changes: 53 additions & 1 deletion src/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
you will be implementing several classes with their correct inheritance heirarchy.

In this file you will be creating three classes:

GameObject
createdAt
dimensions
destroy() // prototype method -> returns the string 'Game object was removed from the game.'


NPC
NPC
hp
name
takeDamage() // prototype method -> returns the string '<object name> took damage.'
Expand Down Expand Up @@ -48,6 +50,56 @@
hamsterHuey.takeDamage(); // returns 'Hamster Huey took damage.'
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
*/
class GameObject {
constructor(obj) {
this.createdAt = obj.createdAt;
this.dimentions = obj.dimentions;
}
destroy() {
return 'Game object was removed from the game.';
}
};
class NPC extends GameObject {
constructor(obj) {
super(obj);
this.hp = obj.hp;
this.name = obj.name;
}
takeDamage() {
return `${this.name} took damage`;
}
destroy() {
return 'Game object was removed from the game.';
}
};
class Humanoid extends NPC {
constructor(obj) {
super(obj);
this.faction = obj.faction;
this.weapons = obj.weapons;
this.language = obj.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
destroy() {
return 'Game object was removed from the game.';
}
takeDamage(par) {
return `${this.name} took damage`;
}
};
let hilal = new Humanoid({
faction: 'aissani',
weapons: 'caboss',
createdAt: 'settara',
dimentions: '2900000',
name: 'hilalala',
language: 'english',
hp: 7
});
console.log(hilal);
console.log(Humanoid.takeDamage());

/* eslint-disable no-undef */

Expand Down
8 changes: 8 additions & 0 deletions src/recursion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
const nFibonacci = (n) => {
// fibonacci sequence: 1 1 2 3 5 8 13 ...
// return the nth number in the sequence
if (n === 0 || n === 1) {
return n;
}
return nFibonacci(n - 1) + nFibonacci(n - 2)
};

const nFactorial = (n) => {
// factorial example: !5 = 5 * 4 * 3 * 2 * 1
// return the factorial of `n`
if (n === 0 || n === 1) {
return n;
}
return n * nFactorial(n - 1);
};

/* Extra Credit */
Expand Down
30 changes: 25 additions & 5 deletions src/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
/* part 1 */

class User {
constructor(options) {
constructor(username, passowrd) {
// set a username and password property on the user object that is created
}
this.username = username;
this.passowrd = password;
};
// create a method on the User class called `checkPassword`
// this method should take in a string and compare it to the object's password property
// return `true` if they match, otherwise return `false`
}

checkPassword = function (string) {
if (string === this.password) {
return true;
}
else {
return false;
}
}
};
const me = new User({
username: 'LambdaSchool',
password: 'correcthorsebatterystaple',
});

const result = me.checkPassword('correcthorsebatterystaple'); // should return `true`

/* part 2 */
Expand All @@ -27,13 +35,25 @@ const checkPassword = function comparePasswords(passwordToCompare) {
// use `this` to access the object's `password` property.
// do not modify this function's parameters
// note that we use the `function` keyword and not `=>`
checkPassword = function (string) {
if (string === this.password) {
return true;
}
else {
return false;
}
}
};

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

// .call
checkPassword.call(User, string);

// .apply
checkPassword.apply(User, arr);

// .bind
newfFunction = checkPassword.bind(User, ...arr);
newFuncrtion();
Loading