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
Binary file added .DS_Store
Binary file not shown.
102 changes: 102 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
// CODE here for your Lambda Classes
class Person {
constructor(main) {
this.name = main.name
this.age = main.age
this.location = main.location
this.gender = main.gender
}

speak() {
return `Hello my name is ${this.name}, I am from from ${this.location}`;
}
}

class Instructor extends Person {
constructor(teacher) {
super(teacher)
this.specialty = teacher.specialty
this.favLanguage = teacher.favLanguage
this.catchPhrase = teacher.catchPhrase
}

demo(subject) {
return `Today we are learning about ${subject}`;
}

grade(student, subject) {
return `${student} receives a perfect score on ${subject}`;
}
}

class Student extends Person {
constructor(student) {
super(student)
this.background = student.previousBackground
this.className = student.className
this.favSubjects = student.favSubjects
}

listsSubjects() {
return this.favSubjects;
}

PRAssignment(subject) {
return `${this.name} has submitted a PR for ${subject}`;
}

sprintChallenge(subject) {
return `${this.name} has begun sprint challenge on ${subject}`;
}
}

class ProjectManagers extends Person {
constructor(pm) {
super(pm)
this.gradClassName = pm.gradClassName
this.favInstructor = pm.favInstructor
}

standUp() {
return `${this.name} announces to {channel}, @channel standy times!`;
}

debugsCode(name, student, subject) {
return `${name} debugs ${student}'s code on ${subject}`;
}
}

const fred = new Instructor({
name: 'Fred',
location: 'Bedrock',
age: 37,
gender: 'male',
favLanguage: 'JavaScript',
specialty: 'Front-end',
catchPhrase: `Don't forget the homies`
});

const alan = new Student({
name: 'Alan',
location: 'Utah',
age: 26,
gender: 'male',
favSubjects: 'JavaScript',
background: "Udacity",
className: "Webpt5"
});

const brandon = new ProjectManagers({
name: 'Brandon',
location: 'Louisiana',
age: 28,
gender: 'male',
gradClassName: "Lambda"
});

console.log(fred.name)
console.log(alan.age)
console.log(fred.catchPhrase)
console.log(brandon.gradClassName)
console.log(fred.demo("JavaScript"))
console.log(alan.sprintChallenge("javaScript Fundamentals"));
console.log(brandon.standUp())
131 changes: 131 additions & 0 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,134 @@ Prototype Refactor
2. Your goal is to refactor all of this code to use ES6 Classes. The console.log() statements should still return what is expected of them.

*/

/*
=== GameObject ===
* createdAt
* name
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

class GameObject {
constructor(main) {
this.name = main.name
this.createdAt = main.createdAt
this.dimensions = main.dimensions
}

destroy() {
return `${this.name} was removed from the game.`;
}
}

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
*/

class CharacterStats extends GameObject {
constructor(info) {
super(info)
this.healthPoints = info.healthPoints
}

takeDamage() {
return `${this.name} took damage.`;
}
}

/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
* weapons
* language
* greet() // prototype method -> returns the string '<object name> offers a greeting in <object language>.'
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

class Humanoid extends CharacterStats {
constructor(stats) {
super(stats)
this.team = stats.team
this.weapons = stats.weapons
this.language = stats.language
}

greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
* Instances of CharacterStats should have all of the same properties as GameObject.
*/

// Test you work by un-commenting these 3 objects and the list of console logs below:


const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 1,
height: 1,
},
healthPoints: 5,
name: 'Bruce',
team: 'Mage Guild',
weapons: [
'Staff of Shamalama',
],
language: 'Common Tongue',
});

const swordsman = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 2,
width: 2,
height: 2,
},
healthPoints: 15,
name: 'Sir Mustachio',
team: 'The Round Table',
weapons: [
'Giant Sword',
'Shield',
],
language: 'Common Tongue',
});

const archer = new Humanoid({
createdAt: new Date(),
dimensions: {
length: 1,
width: 2,
height: 4,
},
healthPoints: 10,
name: 'Lilith',
team: 'Forest Kingdom',
weapons: [
'Bow',
'Dagger',
],
language: 'Elvish',
});

console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
console.log(mage.name); // Bruce
console.log(swordsman.team); // The Round Table
console.log(mage.weapons); // Staff of Shamalama
console.log(archer.language); // Elvish
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
console.log(mage.takeDamage()); // Bruce took damage.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.