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
34 changes: 34 additions & 0 deletions src/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@

// code here

class Use {
constructor(options) {
this.email = options.email;
this.password = options.password;
}

comparePasswords(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.
// `Cat` should extend the `Animal` class.
Expand All @@ -21,6 +37,24 @@

// 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)`;
}
}
/* eslint-disable no-undef */

module.exports = {
Expand Down
58 changes: 58 additions & 0 deletions src/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,64 @@
hamsterHuey.destroy(); // returns 'Game object was removed from the game.'
*/

class GameObject {
constructor() {
this.createdAt = obj.createdAt;
this.dimensions = obj.dimensions;
}
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() {
};
}

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();
takeDamage();
}

const Charlie = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
hp: 5,
name: 'Charlie',
faction: 'Fierce Doggie Tribe',
weapons: [
'passes gas',
],
language: 'Barkish',
});

Charlie.greet(); // return 'Charlie offers a greeting in Barkish'
Charlie.takeDamage(); // return 'Hamster Huey took damage
Charlie.destroy(); // return 'Game object was removed from the game.'


/* eslint-disable no-undef */

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

return fibonacci(num - 1) + fibonacci(num - 2);
}

};

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

};

/* Extra Credit */
Expand Down